Skip to content

Commit 43bc084

Browse files
committed
fix: Add sync commands on bot join build
1 parent c409757 commit 43bc084

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/bot/cogs/admin.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from bot.button_loaders.common import CommonButtonLoader
1616
from bot.cogs.cogs_manager import CogsManager
1717
from bot.core.admin import process_list_modules, process_sync_commands
18+
from bot.utils.console_logger import console_logger
1819
from bot.utils.decorators import admin_only
1920

2021

@@ -149,6 +150,21 @@ async def sync_commands(self, interaction: discord.Interaction):
149150
ctx = await commands.Context.from_interaction(interaction)
150151
await process_sync_commands(ctx)
151152

153+
@commands.Cog.listener()
154+
async def on_guild_join(self, guild: discord.Guild):
155+
"""
156+
Trigger when bot joins a server.
157+
158+
Args:
159+
guild (discord.Guild): The server that the bot is joining.
160+
161+
"""
162+
try:
163+
await self.bot.tree.sync(guild=guild)
164+
console_logger.info(f"Synced commands for guild: {guild.name} ({guild.id})")
165+
except Exception as e:
166+
console_logger.info(f"Failed to sync commands for guild {guild.name}: {e}")
167+
152168

153169
async def setup(bot: commands.Bot):
154170
"""

0 commit comments

Comments
 (0)