From 3ebd1caed7ad702e74e4722bc662eef6498a3404 Mon Sep 17 00:00:00 2001 From: Slipstream Date: Sun, 4 May 2025 21:29:46 -0600 Subject: [PATCH] aa --- cogs/settings_cog.py | 7 +++---- cogs/sync_cog.py | 29 ++++++++++++++++++----------- main.py | 9 ++++----- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/cogs/settings_cog.py b/cogs/settings_cog.py index b0aa68c..3812a92 100644 --- a/cogs/settings_cog.py +++ b/cogs/settings_cog.py @@ -394,10 +394,9 @@ class SettingsCog(commands.Cog, name="Settings"): log.info(f"Commands synced with customizations for guild {guild.id} by {ctx.author.name}") except Exception as e: log.error(f"Failed to sync commands with customizations: {e}") - # Fall back to regular sync if customization sync fails - synced = await self.bot.tree.sync(guild=guild) - await ctx.send(f"Failed to apply customizations, but synced {len(synced)} commands for this server.") - log.info(f"Commands synced (without customizations) for guild {guild.id} by {ctx.author.name}") + # Don't fall back to regular sync to avoid command duplication + await ctx.send(f"Failed to apply customizations. Please check the logs and try again.") + log.info(f"Command sync with customizations failed for guild {guild.id}") except Exception as e: await ctx.send(f"Failed to sync commands: {str(e)}") log.error(f"Failed to sync commands for guild {ctx.guild.id}: {e}") diff --git a/cogs/sync_cog.py b/cogs/sync_cog.py index 31c12e3..de15806 100644 --- a/cogs/sync_cog.py +++ b/cogs/sync_cog.py @@ -2,6 +2,7 @@ import discord from discord.ext import commands from discord import app_commands import traceback +import command_customization class SyncCog(commands.Cog): def __init__(self, bot): @@ -13,7 +14,7 @@ class SyncCog(commands.Cog): async def force_sync(self, ctx): """Force sync all slash commands with verbose output""" await ctx.send("Starting verbose command sync...") - + try: # Get list of commands before sync commands_before = [] @@ -24,16 +25,22 @@ class SyncCog(commands.Cog): "parameters": [p.name for p in cmd.parameters] if hasattr(cmd, "parameters") else [] } commands_before.append(cmd_info) - + await ctx.send(f"Commands before sync: {len(commands_before)}") for cmd_data in commands_before: params_str = ", ".join(cmd_data["parameters"]) await ctx.send(f"- {cmd_data['name']}: {len(cmd_data['parameters'])} params ({params_str})") - - # Perform sync - await ctx.send("Syncing commands...") - synced = await self.bot.tree.sync() - + + # Skip global sync to avoid command duplication + await ctx.send("Skipping global sync to avoid command duplication...") + + # Sync guild-specific commands with customizations + await ctx.send("Syncing guild-specific command customizations...") + guild_syncs = await command_customization.register_all_guild_commands(self.bot) + + total_guild_syncs = sum(len(cmds) for cmds in guild_syncs.values()) + await ctx.send(f"Synced commands for {len(guild_syncs)} guilds with a total of {total_guild_syncs} customized commands") + # Get list of commands after sync commands_after = [] for cmd in self.bot.tree.get_commands(): @@ -43,12 +50,12 @@ class SyncCog(commands.Cog): "parameters": [p.name for p in cmd.parameters] if hasattr(cmd, "parameters") else [] } commands_after.append(cmd_info) - + await ctx.send(f"Commands after sync: {len(commands_after)}") for cmd_data in commands_after: params_str = ", ".join(cmd_data["parameters"]) await ctx.send(f"- {cmd_data['name']}: {len(cmd_data['parameters'])} params ({params_str})") - + # Check for webdrivertorso command specifically wd_cmd = next((cmd for cmd in self.bot.tree.get_commands() if cmd.name == "webdrivertorso"), None) if wd_cmd: @@ -60,8 +67,8 @@ class SyncCog(commands.Cog): await ctx.send(f" Choices: {choices_str}") else: await ctx.send("Webdrivertorso command not found after sync!") - - await ctx.send(f"Synced {len(synced)} command(s) successfully!") + + await ctx.send(f"Synced {total_guild_syncs} command(s) successfully!") except Exception as e: await ctx.send(f"Error during sync: {str(e)}") await ctx.send(f"```{traceback.format_exc()}```") diff --git a/main.py b/main.py index a84be57..17f5e92 100644 --- a/main.py +++ b/main.py @@ -125,11 +125,10 @@ async def on_ready(): commands_before = [cmd.name for cmd in bot.tree.get_commands()] print(f"Commands before sync: {commands_before}") - # Sync global commands first - synced_global = await bot.tree.sync() - print(f"Synced {len(synced_global)} global command(s)") + # Skip global command sync to avoid duplication + print("Skipping global command sync to avoid command duplication...") - # Now sync guild-specific commands with customizations + # Only sync guild-specific commands with customizations print("Syncing guild-specific command customizations...") guild_syncs = await command_customization.register_all_guild_commands(bot) @@ -138,7 +137,7 @@ async def on_ready(): # List commands after sync commands_after = [cmd.name for cmd in bot.tree.get_commands()] - print(f"Global commands after sync: {commands_after}") + print(f"Commands registered in command tree: {commands_after}") except Exception as e: print(f"Failed to sync commands: {e}")