From 59bde86d20948a37444b8098a0ef85a47014ec0e Mon Sep 17 00:00:00 2001 From: Benjamyn Date: Thu, 27 Aug 2026 16:53:56 +1000 Subject: [PATCH] fix: use bot.process_commands() for prefix command dispatch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Removed manual prefix stripping and bot._commands lookup - Simply call bot.process_commands(message) in on_message - This is the standard discord.py way to handle prefix commands - bot.process_commands() internally: strips prefix → finds command → invokes it - This separates prefix commands from slash commands completely --- main.py | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/main.py b/main.py index ed5e5fc..725d98f 100644 --- a/main.py +++ b/main.py @@ -142,7 +142,6 @@ async def hello_command(ctx: commands.Context, name: str = "World") -> None: @bot.command(name="list-commands", description="List all available commands.") async def list_commands(ctx: commands.Context) -> None: """List all available commands.""" - # Get all registered commands (both prefix and slash) cmds = list(bot.commands.values()) cmd_list = [] for cmd in cmds: @@ -209,36 +208,10 @@ async def on_message(message: discord.Message) -> None: if message.guild is None: return - # Check if the message starts with the command prefix (exactly one !) - if message.content.startswith("!."): - # Strip ONLY the first '!' character - content = message.content[1:] - - # 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.") + # Call bot.process_commands() — this handles PREFIX COMMANDS + # It strips the prefix, finds the command, and invokes it. + # This is the CORRECT way to handle prefix commands in discord.py. + await bot.process_commands(message) @bot.event