Skip to content

Commit 482fa79

Browse files
committed
fix: Fix setup logic re-running on bot reconnect
1 parent 994e5c7 commit 482fa79

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

src/bot/main.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,35 @@
3737
# Initialize cog manager
3838
cogs_manager = CogsManager(bot)
3939

40+
# Flag if bot startup is complete
41+
bot_startup_complete = False
42+
4043

4144
@bot.event
4245
async def on_ready():
4346
"""
4447
Handle bot ready event.
4548
"""
46-
console_logger.info(f"Logged in as {bot.user} (ID: {bot.user.id})")
47-
48-
# Initialize DB and ticket counters
49-
await init_db()
50-
bot.loop.create_task(initialize_ticket_counter_table())
51-
52-
# Load all cogs
53-
await cogs_manager.load_all_cogs()
54-
55-
# Log readiness and available commands
56-
console_logger.info(f"Bot is ready with {len(bot.tree.get_commands())} command(s) loaded:")
57-
for cmd in bot.tree.get_commands():
58-
console_logger.info(f"Command loaded: {cmd.name}")
49+
# Run logic only if bot startup is incomplete
50+
global bot_startup_complete
51+
if not bot_startup_complete:
52+
console_logger.info(f"Logged in as {bot.user} (ID: {bot.user.id})")
53+
54+
# Initialize DB and ticket counters
55+
await init_db()
56+
bot.loop.create_task(initialize_ticket_counter_table())
57+
58+
# Load all cogs
59+
await cogs_manager.load_all_cogs()
60+
61+
# Log readiness and available commands
62+
console_logger.info(f"Bot is ready with {len(bot.tree.get_commands())} command(s) loaded:")
63+
for cmd in bot.tree.get_commands():
64+
console_logger.info(f"Command loaded: {cmd.name}")
65+
66+
bot_startup_complete = True
67+
else:
68+
console_logger.info("Reconnected to Discord.")
5969

6070

6171
# Run the bot using the token from .env

0 commit comments

Comments
 (0)