Refactor slash command synchronization logic to prevent duplicate commands in Discord. Update environment variables for command sync modes and enhance command clearing functionality. Improve command registration handling in the bot to streamline user experience.
Some checks failed
CI / Bot (Python) (push) Successful in 12s
CI / Dashboard (Next.js) (push) Failing after 9s

This commit is contained in:
TheOnlyMace
2026-07-21 22:53:51 +02:00
parent 1da2085087
commit a52d84467d
5 changed files with 130 additions and 90 deletions

View File

@@ -303,28 +303,29 @@ class Owner(commands.Cog):
@commands.hybrid_command(name="syncslash", help="Re-register all slash (/) commands with Discord.")
@commands.is_owner()
async def syncslash(self, ctx, scope: str = "all"):
"""Force-sync slash commands. scope: all | global | guild"""
"""Force-sync slash commands. scope: all | global | clear"""
if ctx.interaction:
await ctx.defer(ephemeral=True)
from utils.slash_sync import sync_slash_commands
scope = (scope or "all").lower().strip()
if scope == "global":
result = await sync_slash_commands(self.client, guilds=[], global_sync=True)
elif scope == "guild":
if not ctx.guild:
return await ctx.send("Use this in a server, or pass scope `all` / `global`.")
result = await sync_slash_commands(
self.client, guilds=[ctx.guild], global_sync=False
)
result = await sync_slash_commands(self.client, guilds=list(self.client.guilds), global_sync=True)
elif scope in ("guild", "clear"):
# Clear guild-scoped copies in this server (or all) to remove duplicates
targets = [ctx.guild] if ctx.guild and scope == "clear" else list(self.client.guilds)
if not targets:
return await ctx.send("No guild to clear.")
result = await sync_slash_commands(self.client, guilds=targets, global_sync=(scope != "clear"))
else:
result = await sync_slash_commands(self.client)
guild_n = len(result.get("guilds") or {})
cleared = len(result.get("cleared_guilds") or [])
err_n = len(result.get("errors") or [])
await ctx.send(
f"{TICK} Slash sync done — tree `{result.get('local_tree')}`, "
f"global `{result.get('global')}`, guilds `{guild_n}`, errors `{err_n}`."
f"{TICK} Slash sync done — mode `{result.get('mode')}`, "
f"tree `{result.get('local_tree')}`, global `{result.get('global')}`, "
f"cleared guilds `{cleared}`, errors `{err_n}`."
)