feat(bot): ✨ Move DB initialization and Redis connection testing outside of on_ready to run.py's shard() function.

This commit is contained in:
Nyeki.py
2024-10-28 14:40:38 -03:00
parent 38aa6d1f55
commit 0c52d69559
2 changed files with 9 additions and 8 deletions
+1 -8
View File
@@ -74,16 +74,9 @@ class Payphone(commands.AutoShardedBot):
) )
async def on_ready(self) -> None: async def on_ready(self) -> None:
"""Initializes the bot. """Runs when the bot has finished initializing.
Initializes the bot's DB and connects to Redis, and then prints a ready message to the
console.
""" """
await setup.init()
await self.redis.ping()
self.log.info("Ready! Logged in as %s.", self.user.display_name) self.log.info("Ready! Logged in as %s.", self.user.display_name)
async def on_shard_ready(self, shard_id: int) -> None: async def on_shard_ready(self, shard_id: int) -> None:
+8
View File
@@ -26,6 +26,7 @@ def shard(
shut down soon. shut down soon.
""" """
from payphone.db import setup
from payphone.bot import bot from payphone.bot import bot
from payphone.core import config from payphone.core import config
@@ -37,6 +38,13 @@ def shard(
log.info("Running shard %s with default loop.", shard_id) log.info("Running shard %s with default loop.", shard_id)
bot.loop.set_debug(True) bot.loop.set_debug(True)
async def initialize():
await setup.init()
await bot.redis.ping()
bot.loop.run_until_complete(initialize())
bot.run(config.TOKEN) bot.run(config.TOKEN)