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