Example code for connecting to and using a postgres database using discord.py an...
source link: https://gist.github.com/jegfish/cfc7b22e72426f5ced6f87caa6920fd6
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Author
jegfish commented on Aug 1, 2018
@xMont4hdaRxon_ready
can be called multiple times. Other events where you may check your database can be called before on_ready
.
The main reason I did it the way I did is because at the time of me writing this gist I was looking at an example of sub-classing bot.
You do not have to do it this way, it is just an example.
If you wanted to do it with on_ready
you could check within there if the database is already declared in case of it running multiple times and add an await bot.wait_until_ready()
to the beginning of any event (such as on_message
, which would also apply to commands assuming you override the default on_message
with an event instead of listener) where you access the database.
While I won't say the way I do it is the best, I will say it feels better than doing it in on_ready
as you do not have to check that the database connection hasn't already been opened.
Recommend
-
65
This blog is the source for news about major Java announcements and the Java community.
-
33
Serverless from the ground up: Connecting Cloud Functions with...
-
7
Connecting efficiently to Azure Database for MySQL with ProxySQL%3CLINGO-SUB%20id%3D%22lingo-sub-1279842%22%20slang%3D%22en-US%22%3EConnecting%20efficiently%20to%20Azure%20Database%20for%20MySQL%20with%20ProxySQL%3C%2FLINGO-SUB%3E%3CLINGO-BODY%2...
-
5
Connecting to managed Database Services via TLS This article describes how to use a managed PostgreSQL database in a Quarkus microservice and how to handle TLS certificates. In my
-
7
Running a safe database migration using Postgres Peter Johnston 1 March 2021...
-
6
Connecting to a database using a third-party program Overview The following describes how to connect to your DreamHost database(s) using a third-party program.
-
5
Connecting Red Hat Single Sign-on on Openshift to an External Database ...
-
8
October 25, 2021 /
-
4
This article was published as a part of the Data Science Blogathon. Introduction Supabase is an open-source Backend as a Service (BaaS) that is gaining traction am...
-
6
Setup Sonarqube with Postgres database using docker
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK