7

Example code for connecting to and using a postgres database using discord.py an...

 1 year ago
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.
neoserver,ios ssh client

Author

jegfish commented on Aug 1, 2018

@xMont4hdaRx
on_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

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK