【问题标题】:Detect Word Then Send Message (discord.py)检测单词然后发送消息 (discord.py)
【发布时间】:2020-04-19 13:12:00
【问题描述】:

我试图让我的机器人在输入时检测到“哇”这个词,然后用“哦哇”做出回应,但我不知道该怎么做,在互联网上搜索答案对我没有帮助因为通常他们不会尝试专门做我正在做的事情。

这是我现在的代码

#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

【问题讨论】:

  • 那么出了什么问题?你做过调试吗?什么是 message.content?
  • 您是否在某处定义了channel,或者您打算使用message.channel.send?您是否看到错误消息?

标签: python discord chatbot discord.py discord.py-rewrite


【解决方案1】:

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

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

@client.event
async def on_message(message):

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

【讨论】:

    猜你喜欢
    • 2021-10-13
    • 2020-12-26
    • 1970-01-01
    • 2021-07-08
    • 1970-01-01
    • 2022-01-07
    • 2020-11-10
    • 2020-10-31
    • 2017-08-15
    相关资源
    最近更新 更多