From 0c52d69559bf6f9e5094eb788a0a8e194c587ab8 Mon Sep 17 00:00:00 2001 From: "Nyeki.py" <84998222+Nekidev@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:40:38 -0300 Subject: [PATCH] feat(bot): :sparkles: Move DB initialization and Redis connection testing outside of `on_ready` to `run.py`'s `shard()` function. --- payphone/bot.py | 9 +-------- run.py | 8 ++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/payphone/bot.py b/payphone/bot.py index 836a8b3..d89c5d0 100644 --- a/payphone/bot.py +++ b/payphone/bot.py @@ -74,16 +74,9 @@ class Payphone(commands.AutoShardedBot): ) async def on_ready(self) -> None: - """Initializes the bot. - - Initializes the bot's DB and connects to Redis, and then prints a ready message to the - console. + """Runs when the bot has finished initializing. """ - await setup.init() - - await self.redis.ping() - self.log.info("Ready! Logged in as %s.", self.user.display_name) async def on_shard_ready(self, shard_id: int) -> None: diff --git a/run.py b/run.py index aa4b84d..628773f 100644 --- a/run.py +++ b/run.py @@ -26,6 +26,7 @@ def shard( shut down soon. """ + from payphone.db import setup from payphone.bot import bot from payphone.core import config @@ -37,6 +38,13 @@ def shard( log.info("Running shard %s with default loop.", shard_id) 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)