debug: add comprehensive logging for command registration and sync

- Added _log_registered_commands() to list all commands in tree
- Added logging in __init__ to track command registration
- Enhanced on_ready() sync logging with detailed information
- Shows registered commands before and during sync
- Shows specific guild sync status with command counts
- Added error handling for Forbidden errors (missing permissions)
- Clear warnings when no guilds are synced
This commit is contained in:
2026-01-31 16:40:23 -06:00
parent 9f14e8c745
commit 85f3e79d2a

57
bot.py
View File

@@ -58,11 +58,26 @@ class TTSBot(commands.Bot):
self.message_queue: asyncio.Queue[tuple[discord.Message, str] | tuple[discord.Message, str, str]] = asyncio.Queue()
self.last_activity: float = 0.0
print("\n=== Command Registration ===")
self._setup_slash_commands()
self._setup_effects_commands()
self._log_registered_commands()
print("=== End Command Registration ===\n")
def _log_registered_commands(self) -> None:
"""Log all registered commands to console."""
print("\nRegistered commands:")
commands = list(self.tree.get_commands())
if not commands:
print(" ⚠️ No commands registered!")
else:
for cmd in commands:
print(f" ✓ /{cmd.name} - {cmd.description}")
print(f"\nTotal commands registered: {len(commands)}")
def _setup_slash_commands(self) -> None:
"""Set up slash commands for voice management."""
print("Setting up voice commands...")
@self.tree.command(name="voice", description="Manage your TTS voice")
@app_commands.describe(
@@ -110,6 +125,7 @@ class TTSBot(commands.Bot):
def _setup_effects_commands(self) -> None:
"""Set up slash commands for audio effects management."""
print("Setting up effects commands...")
@self.tree.command(name="effects", description="Manage your TTS audio effects")
@app_commands.describe(
@@ -499,16 +515,45 @@ class TTSBot(commands.Bot):
self.loop.create_task(self.process_queue())
self.loop.create_task(self.check_inactivity())
# Sync slash commands
print("Syncing slash commands...")
await self.tree.sync()
print("Slash commands synced!")
async def on_ready(self) -> None:
print(f"Logged in as {self.user}")
print(f"Bot ID: {self.user.id}")
print(f"Monitoring channel ID: {Config.TEXT_CHANNEL_ID}")
print(f"Available voices: {', '.join(self.voice_manager.get_available_voices())}")
print("Bot is ready!")
# Log registered commands before sync
registered_cmds = list(self.tree.get_commands())
print(f"\nCommands in tree before sync: {len(registered_cmds)}")
for cmd in registered_cmds:
print(f" - /{cmd.name}")
# Sync slash commands to each guild for immediate availability
print(f"\nConnected to {len(self.guilds)} guild(s):")
for guild in self.guilds:
print(f" - {guild.name} (ID: {guild.id})")
print("\nSyncing slash commands to guilds...")
sync_count = 0
for guild in self.guilds:
try:
synced = await self.tree.sync(guild=discord.Object(guild.id))
print(f" ✓ Synced {len(synced)} commands to guild: {guild.name}")
for cmd in synced:
print(f" - /{cmd.name}")
sync_count += 1
except discord.errors.Forbidden as e:
print(f" ✗ Forbidden: Cannot sync to guild {guild.name}. Missing 'applications.commands' scope!")
print(f" Error: {e}")
except Exception as e:
print(f" ✗ Failed to sync to guild {guild.name}: {type(e).__name__}: {e}")
if sync_count == 0:
print("\n⚠️ WARNING: No guilds were synced! Commands won't appear in Discord.")
print(" Make sure the bot was invited with 'applications.commands' scope.")
else:
print(f"\n✓ Successfully synced to {sync_count}/{len(self.guilds)} guild(s)")
print("\nBot is ready!")
async def on_message(self, message: discord.Message) -> None:
if message.author.bot: