fix: use copy_global_to before guild sync for immediate command availability

The issue: Commands registered as global commands weren't being synced
when calling tree.sync(guild=...) because they weren't associated with
the specific guild context.

The fix: Call tree.copy_global_to(guild=...) before sync() to copy global
commands to each guild's context. This makes commands appear immediately
instead of requiring global sync (which can take up to 1 hour).

Reference: discord.py FAQ recommends copy_global_to for development
when you want immediate command availability in specific guilds.
This commit is contained in:
2026-01-31 16:43:10 -06:00
parent 85f3e79d2a
commit f082c62a16

5
bot.py
View File

@@ -536,6 +536,11 @@ class TTSBot(commands.Bot):
sync_count = 0 sync_count = 0
for guild in self.guilds: for guild in self.guilds:
try: try:
# Copy global commands to this guild before syncing
# This is necessary for guild-specific command registration
self.tree.copy_global_to(guild=discord.Object(guild.id))
print(f" 📋 Copied global commands to guild: {guild.name}")
synced = await self.tree.sync(guild=discord.Object(guild.id)) synced = await self.tree.sync(guild=discord.Object(guild.id))
print(f" ✓ Synced {len(synced)} commands to guild: {guild.name}") print(f" ✓ Synced {len(synced)} commands to guild: {guild.name}")
for cmd in synced: for cmd in synced: