Update invite links to use dynamic Discord client ID and import necessary configuration constants. Refactor slash command synchronization logic for improved error handling and performance.
Some checks failed
CI / Bot (Python) (push) Failing after 12s
CI / Dashboard (Next.js) (push) Failing after 10s

This commit is contained in:
TheOnlyMace
2026-07-21 22:44:40 +02:00
parent fc77f0a3c2
commit 6b0091f7d5
3 changed files with 14 additions and 14 deletions

View File

@@ -119,31 +119,29 @@ async def sync_slash_commands(
"pruned": removed,
}
async def _try_sync(label: str, coro):
async def _try_sync(label: str, factory):
try:
synced = await coro
synced = await factory()
return synced, None
except Exception as e:
# Drop invalid commands once and retry (common after bulk hybrid conversion)
detail = str(e)
logger.error("%s failed: %s", label, detail)
dropped = []
for cmd in list(bot.tree.get_commands()):
# Heuristic: remove cmds whose name appears in the error payload
if cmd.name in detail or getattr(cmd, "qualified_name", "") in detail:
bot.tree.remove_command(cmd.name)
dropped.append(cmd.name)
if dropped:
print(f"\033[33m◈ Removed invalid slash cmd(s) after error: {', '.join(dropped)}\033[0m")
try:
synced = await coro
synced = await factory()
return synced, None
except Exception as e2:
return None, f"{label}: {e2}"
return None, f"{label}: {e}"
if do_global:
synced, err = await _try_sync("Global slash sync", bot.tree.sync())
synced, err = await _try_sync("Global slash sync", lambda: bot.tree.sync())
if err:
result["errors"].append(err)
print(f"\033[31m◈ {err}\033[0m")
@@ -162,11 +160,13 @@ async def sync_slash_commands(
for guild in target_guilds:
gid = getattr(guild, "id", guild)
async def _guild_sync(g=guild):
bot.tree.copy_global_to(guild=g)
return await bot.tree.sync(guild=g)
def _make_factory(g=guild):
async def _factory():
bot.tree.copy_global_to(guild=g)
return await bot.tree.sync(guild=g)
return _factory
synced, err = await _try_sync(f"Guild {gid} slash sync", _guild_sync())
synced, err = await _try_sync(f"Guild {gid} slash sync", _make_factory())
if err:
result["errors"].append(err)
print(f"\033[31m◈ {err}\033[0m")