Skip to content

Commit 5322a0a

Browse files
committed
fix(serve): use guild-scoped slash command sync for instant registration
Global tree.sync() can take hours to propagate across Discord's infrastructure. Switch to per-guild tree.sync(guild=guild) which registers commands instantly, matching how discord.py bots typically handle slash command registration.
1 parent fc2dcbc commit 5322a0a

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "discord-cli-agent"
7-
version = "0.5.1"
7+
version = "0.5.2"
88
description = "Discord CLI for AI agents"
99
readme = "README.md"
1010
license = "MIT"

src/discli/commands/serve.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,15 @@ async def slash_handler_no_args(interaction: discord.Interaction):
283283
"interaction_token": itk,
284284
})
285285

286-
await tree.sync()
287-
emit({"event": "slash_commands_synced", "count": len(slash_defs)})
286+
# Sync per guild for instant registration (global sync can take hours)
287+
synced_guilds = 0
288+
for guild in client.guilds:
289+
try:
290+
await tree.sync(guild=guild)
291+
synced_guilds += 1
292+
except Exception as e:
293+
emit({"event": "error", "message": f"Failed to sync commands to {guild.name}: {e}"})
294+
emit({"event": "slash_commands_synced", "count": len(slash_defs), "guilds": synced_guilds})
288295

289296
# ── Presence ────────────────────────────────────────────────────
290297

0 commit comments

Comments
 (0)