检测单词然后发送消息 (discord.py)

Detect Word Then Send Message (discord.py)

我只是想让我的机器人在输入时检测单词 "wow",然后用 "oh wow" 进行响应,但我不确定该怎么做并在周围搜索答案互联网对我没有帮助,因为通常他们不会尝试专门做我正在做的事情。

这是我现在的代码

#New Event, prints oh wow if someone says wow
@client.event
async def on_message(message):

    if "wow" in message.content:
        await channel.send("oh wow")

#End of Event

问题是你没有定义频道。为了向频道发送消息,您首先需要定义频道。在这种情况下,您希望将消息发送到与发送消息相同的频道。所以你可以只使用消息对象中的通道对象。

因此您需要进行以下操作:

@client.event
async def on_message(message):

if "wow" in message.content:
    await message.channel.send("oh wow")