我做了一个自动响应特定消息的命令。该命令有效,但它使我所有其他命令无效(discord.py 重写)

I made a command that automatically responds to a specific message. The command works but it makes all my other commands not work (discord.py rewrite)

这是我打招呼时用于命令响应的代码。这会起作用,但如果我在 none 个命令起作用后尝试使用命令,并且如果我将其从我的代码中删除,那么它会再次起作用。使用命令时没有错误代码。我真的不知道如何解决这个问题,有人知道为什么会这样吗?如果是,我该如何解决?

@client.event
async def on_message(message):
    channel = client.get_channel(CHANNEL)
    hello = "hello"
    if message.content.count(hello) > 0:
        message = "Whats up!"
        await channel.send(message)

使用 on_message 事件时,您需要 process_commands() 才能让您的命令生效:

@client.event
async def on_message(message):
    # checking against lower case string will be more consistent with finding more "hello"s
    if message.content.lower().count("hello") > 0:
        await message.channel.send("What's up!")

    await client.process_commands(message)

参考文献:

  • Bot.process_commands() - “如果您选择覆盖 on_message() 事件,那么您也应该调用这个协程。”