diff --git a/bot/src/run.py b/bot/src/run.py index 55febf7..fff78ea 100644 --- a/bot/src/run.py +++ b/bot/src/run.py @@ -74,12 +74,24 @@ class Bot(commands.Bot): name = file[:-3] await self.load_extension(f"cogs.{name}") - # Sync slash commands + # Sync slash commands. A sync only replaces the commands in its own scope, so commands left + # in the other scope (global or guild) from running in the other mode show up as duplicates + guild = discord.Object(id=self.guild_id) if os.environ.get("BOT_CONFIG_MODE") == "prod": await self.tree.sync() + try: + self.tree.clear_commands(guild=guild) + await self.tree.sync(guild=guild) + except discord.HTTPException as e: + self.logger.warning(f"Could not remove leftover guild commands in {self.guild_id}: {e}") else: - self.tree.copy_global_to(guild=discord.Object(id=self.guild_id)) - await self.tree.sync(guild=discord.Object(id=self.guild_id)) + self.tree.copy_global_to(guild=guild) + await self.tree.sync(guild=guild) + if global_commands := await self.tree.fetch_commands(): + self.logger.warning( + f"This bot application also has {len(global_commands)} global slash commands, which show up " + + "twice in the dev guild. Use a separate bot application for development" + ) async def __aexit__(self, *args): """