This commit is contained in:
Slipstream 2025-05-04 21:29:46 -06:00
parent 2ec585ff81
commit 3ebd1caed7
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD
3 changed files with 25 additions and 20 deletions

View File

@ -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}") log.info(f"Commands synced with customizations for guild {guild.id} by {ctx.author.name}")
except Exception as e: except Exception as e:
log.error(f"Failed to sync commands with customizations: {e}") log.error(f"Failed to sync commands with customizations: {e}")
# Fall back to regular sync if customization sync fails # Don't fall back to regular sync to avoid command duplication
synced = await self.bot.tree.sync(guild=guild) await ctx.send(f"Failed to apply customizations. Please check the logs and try again.")
await ctx.send(f"Failed to apply customizations, but synced {len(synced)} commands for this server.") log.info(f"Command sync with customizations failed for guild {guild.id}")
log.info(f"Commands synced (without customizations) for guild {guild.id} by {ctx.author.name}")
except Exception as e: except Exception as e:
await ctx.send(f"Failed to sync commands: {str(e)}") await ctx.send(f"Failed to sync commands: {str(e)}")
log.error(f"Failed to sync commands for guild {ctx.guild.id}: {e}") log.error(f"Failed to sync commands for guild {ctx.guild.id}: {e}")

View File

@ -2,6 +2,7 @@ import discord
from discord.ext import commands from discord.ext import commands
from discord import app_commands from discord import app_commands
import traceback import traceback
import command_customization
class SyncCog(commands.Cog): class SyncCog(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
@ -13,7 +14,7 @@ class SyncCog(commands.Cog):
async def force_sync(self, ctx): async def force_sync(self, ctx):
"""Force sync all slash commands with verbose output""" """Force sync all slash commands with verbose output"""
await ctx.send("Starting verbose command sync...") await ctx.send("Starting verbose command sync...")
try: try:
# Get list of commands before sync # Get list of commands before sync
commands_before = [] commands_before = []
@ -24,16 +25,22 @@ class SyncCog(commands.Cog):
"parameters": [p.name for p in cmd.parameters] if hasattr(cmd, "parameters") else [] "parameters": [p.name for p in cmd.parameters] if hasattr(cmd, "parameters") else []
} }
commands_before.append(cmd_info) commands_before.append(cmd_info)
await ctx.send(f"Commands before sync: {len(commands_before)}") await ctx.send(f"Commands before sync: {len(commands_before)}")
for cmd_data in commands_before: for cmd_data in commands_before:
params_str = ", ".join(cmd_data["parameters"]) params_str = ", ".join(cmd_data["parameters"])
await ctx.send(f"- {cmd_data['name']}: {len(cmd_data['parameters'])} params ({params_str})") await ctx.send(f"- {cmd_data['name']}: {len(cmd_data['parameters'])} params ({params_str})")
# Perform sync # Skip global sync to avoid command duplication
await ctx.send("Syncing commands...") await ctx.send("Skipping global sync to avoid command duplication...")
synced = await self.bot.tree.sync()
# 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 # Get list of commands after sync
commands_after = [] commands_after = []
for cmd in self.bot.tree.get_commands(): 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 [] "parameters": [p.name for p in cmd.parameters] if hasattr(cmd, "parameters") else []
} }
commands_after.append(cmd_info) commands_after.append(cmd_info)
await ctx.send(f"Commands after sync: {len(commands_after)}") await ctx.send(f"Commands after sync: {len(commands_after)}")
for cmd_data in commands_after: for cmd_data in commands_after:
params_str = ", ".join(cmd_data["parameters"]) params_str = ", ".join(cmd_data["parameters"])
await ctx.send(f"- {cmd_data['name']}: {len(cmd_data['parameters'])} params ({params_str})") await ctx.send(f"- {cmd_data['name']}: {len(cmd_data['parameters'])} params ({params_str})")
# Check for webdrivertorso command specifically # Check for webdrivertorso command specifically
wd_cmd = next((cmd for cmd in self.bot.tree.get_commands() if cmd.name == "webdrivertorso"), None) wd_cmd = next((cmd for cmd in self.bot.tree.get_commands() if cmd.name == "webdrivertorso"), None)
if wd_cmd: if wd_cmd:
@ -60,8 +67,8 @@ class SyncCog(commands.Cog):
await ctx.send(f" Choices: {choices_str}") await ctx.send(f" Choices: {choices_str}")
else: else:
await ctx.send("Webdrivertorso command not found after sync!") 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: except Exception as e:
await ctx.send(f"Error during sync: {str(e)}") await ctx.send(f"Error during sync: {str(e)}")
await ctx.send(f"```{traceback.format_exc()}```") await ctx.send(f"```{traceback.format_exc()}```")

View File

@ -125,11 +125,10 @@ async def on_ready():
commands_before = [cmd.name for cmd in bot.tree.get_commands()] commands_before = [cmd.name for cmd in bot.tree.get_commands()]
print(f"Commands before sync: {commands_before}") print(f"Commands before sync: {commands_before}")
# Sync global commands first # Skip global command sync to avoid duplication
synced_global = await bot.tree.sync() print("Skipping global command sync to avoid command duplication...")
print(f"Synced {len(synced_global)} global command(s)")
# Now sync guild-specific commands with customizations # Only sync guild-specific commands with customizations
print("Syncing guild-specific command customizations...") print("Syncing guild-specific command customizations...")
guild_syncs = await command_customization.register_all_guild_commands(bot) guild_syncs = await command_customization.register_all_guild_commands(bot)
@ -138,7 +137,7 @@ async def on_ready():
# List commands after sync # List commands after sync
commands_after = [cmd.name for cmd in bot.tree.get_commands()] 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: except Exception as e:
print(f"Failed to sync commands: {e}") print(f"Failed to sync commands: {e}")