Update bot manager to respond to start bot when bot is ready
Some checks failed
Lint / lint (push) Waiting to run
release-tag / release-image (push) Has been cancelled

This commit is contained in:
Logan Cusano
2025-04-27 03:15:15 -04:00
parent 75b2d0007d
commit 46ec27c359

View File

@@ -36,6 +36,8 @@ class DiscordBotManager:
@self.bot.event
async def on_ready():
LOGGER.info(f'Logged in as {self.bot.user}')
# Set the event when on_ready is called
self._ready_event.set()
@self.bot.event
async def on_voice_state_update(member, before, after):
@@ -49,13 +51,30 @@ class DiscordBotManager:
LOGGER.warning(f"Error leaving voice channel: '{e}'")
# Attempt to reconnect to the channel after a brief pause
await asyncio.sleep(2)
# You might need to store the previous channel ID more robustly
# for reconnection attempts in a real application
await self.join_voice_channel(guild_id, before.channel.id)
# Load Opus for the current CPU
# Load Opus for the current CPU
await self.load_opus()
# Create the task to run the bot in the background
self.bot_task = self.loop.create_task(self.bot.start(token))
# Wait for the on_ready event to be set by the bot task
LOGGER.info("Waiting for bot to become ready...")
try:
# Add a timeout for robustness in case on_ready never fires
await asyncio.wait_for(self._ready_event.wait(), timeout=60.0) # Adjust timeout as needed
LOGGER.info("Bot is ready, start_bot returning.")
except asyncio.TimeoutError:
LOGGER.error("Timeout waiting for bot to become ready. Bot might have failed to start.")
# Optionally cancel the bot task if it didn't become ready
if self.bot_task and not self.bot_task.done():
self.bot_task.cancel()
raise RuntimeError("Bot failed to become ready within timeout.")
async def stop_bot(self):
async with self.lock:
if self.bot: