【问题标题】:How to make a Discord Bot respond when two conditions are both met?当两个条件都满足时,如何让 Discord Bot 做出响应?
【发布时间】:2021-04-10 15:00:52
【问题描述】:

我正在使用 discord.py 和 repl.it 开发一个基本的不和谐机器人,并试图让一个基本的响应系统运行起来。基本上,我试图让它查看两个列表中的单词,并且仅在从两个列表中获取单词时才回复。现在我的代码如下所示:

    if any(word in msg for word in mean and bidoof):
      await message.channel.send(random.choice(bidoof_angry))

我尝试使用“and”运算符从“mean”和“bidoof”中提取单词,但它的表现几乎就像我认为“或”应该的那样。当它从“bidoof”列表中看到一个词时,它会回复,即使消息中没有来自另一个列表的词。我对此很陌生,因此非常感谢任何帮助。

【问题讨论】:

    标签: python discord discord.py bots


    【解决方案1】:

    很简单!只需使用 AND 运算符。

     if any(word in msg for word in mean) and bidoof:
        await message.channel.send(random.choice(bidoof_angry))
    

    如果您要检查 bidoof 是否为 True,上面的代码应该可以工作。

    【讨论】:

    • 你不需要is True,你可以写成and bidoof:
    • 谢谢!我没注意到!
    • 不客气,别忘了编辑你的答案:)
    猜你喜欢
    • 2021-06-13
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-07
    相关资源
    最近更新 更多