0

I am writing a discord bot and it needs access to 2 databases, but after a while the connection closes and the commands stop working. I wrote a code that executes this line every 100 seconds, but I think it's wrong.

@Cog.listener()
async def on_ready(self) -> None:
    if not self.ping_databases.is_running():
        self.ping_databases.start()

@tasks.loop(seconds=60)
async def ping_databases(self):
    if Config.DATABASE_AUTORECONNECT:
        database_mta.connection.ping(reconnect=True)
        database_bot.connection.ping(reconnect=True)

I also tried to execute it in on_slash_command, but the commands are executed faster than the second database has time to connect.

ANTI
  • 3
  • 1

0 Answers0