fix: await bot.process_commands(message) in on_message
- The on_message handler was calling process_commands() without await - Without await, the coroutine returned immediately and the command never ran - Now the command is properly processed and a response is sent
This commit is contained in:
parent
00cdad3145
commit
1c27ed17cf
5
main.py
5
main.py
@ -140,7 +140,7 @@ async def hello_command(ctx: commands.Context, name: str = "World") -> None:
|
|||||||
await ctx.send(f"Hello, {name}!")
|
await ctx.send(f"Hello, {name}!")
|
||||||
|
|
||||||
@bot.command(name="list-commands", description="List all available commands.")
|
@bot.command(name="list-commands", description="List all available commands.")
|
||||||
async def help_command(ctx: commands.Context) -> None:
|
async def list_commands(ctx: commands.Context) -> None:
|
||||||
"""List all available commands."""
|
"""List all available commands."""
|
||||||
# Get all registered commands (both prefix and slash)
|
# Get all registered commands (both prefix and slash)
|
||||||
cmds = list(bot.commands.values())
|
cmds = list(bot.commands.values())
|
||||||
@ -180,7 +180,7 @@ async def on_command_error(ctx: commands.Context, error: commands.CommandError)
|
|||||||
"""Global error handler for all commands."""
|
"""Global error handler for all commands."""
|
||||||
logger.debug(f"Command error for {ctx.author.name} ({ctx.author.id}): {error}")
|
logger.debug(f"Command error for {ctx.author.name} ({ctx.author.id}): {error}")
|
||||||
if isinstance(error, commands.CommandNotFound):
|
if isinstance(error, commands.CommandNotFound):
|
||||||
await ctx.send("Command not found. Type `!help` for a list of commands.")
|
await ctx.send("Command not found. Type `!list-commands` for a list of commands.")
|
||||||
elif isinstance(error, commands.CheckFailure):
|
elif isinstance(error, commands.CheckFailure):
|
||||||
await ctx.send("You do not have permission to use this command.")
|
await ctx.send("You do not have permission to use this command.")
|
||||||
elif isinstance(error, commands.MissingPermissions):
|
elif isinstance(error, commands.MissingPermissions):
|
||||||
@ -215,6 +215,7 @@ async def on_message(message: discord.Message) -> None:
|
|||||||
content = message.content[1:]
|
content = message.content[1:]
|
||||||
# Remove the leading "!" again since we stripped one
|
# Remove the leading "!" again since we stripped one
|
||||||
content = content.lstrip("!")
|
content = content.lstrip("!")
|
||||||
|
# FIX: Await process_commands to actually process the command
|
||||||
await bot.process_commands(message)
|
await bot.process_commands(message)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user