From 6f8ed88f7acc9f708ea6db4ff0423337d5d60561 Mon Sep 17 00:00:00 2001 From: Benjamyn Date: Thu, 27 Aug 2026 16:50:16 +1000 Subject: [PATCH] fix: use bot._commands registry to find prefix commands - Changed on_message handler to use bot._commands.get(content) instead of bot.get_command() - bot._commands is the internal command registry that stores commands by their exact name - This properly routes prefix commands to their handlers without relying on process_commands() - Fixes: commands were not being invoked because process_commands() doesn't route to prefix commands --- main.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index c052640..ed5e5fc 100644 --- a/main.py +++ b/main.py @@ -200,7 +200,7 @@ async def on_command_error(ctx: commands.Context, error: commands.CommandError) @bot.event async def on_message(message: discord.Message) -> None: - """Handle text messages sent in channels.""" + """Handle text messages sent in channels (prefix commands).""" # Ignore bot's own messages if message.author == bot.user: return @@ -211,10 +211,34 @@ async def on_message(message: discord.Message) -> None: # Check if the message starts with the command prefix (exactly one !) if message.content.startswith("!."): - # Strip ONLY the first "!" character (not all of them) + # Strip ONLY the first '!' character content = message.content[1:] - # Now process the command - await bot.process_commands(message) + + # Find the matching command by name from the bot's internal command registry + command = bot._commands.get(content) + + if command is not None: + logger.debug(f"Found command: {command.name}") + # Create a minimal context for the command + ctx = commands.Context(bot=bot, channel=message.channel, message=message, guild=message.guild) + # Call the command directly (bypassing prefix parsing) + await command.invoke(ctx) + else: + logger.debug(f"No command found for: {content}") + await message.channel.send("Command not found. Type `!list-commands` for a list of commands.") + else: + # Message doesn't start with '!', check for normal prefix commands + if message.content.startswith("!"): + content = message.content[1:] + command = bot._commands.get(content) + + if command is not None: + logger.debug(f"Found command: {command.name}") + ctx = commands.Context(bot=bot, channel=message.channel, message=message, guild=message.guild) + await command.invoke(ctx) + else: + logger.debug(f"No command found for: {content}") + await message.channel.send("Command not found. Type `!list-commands` for a list of commands.") @bot.event