[英]How to make a Discord Bot respond when two conditions are both met?
I'm working on a basic discord bot using discord.py and repl.it, and am trying to get a basic response system going.我正在使用 discord.py 和 repl.it 开发一个基本的 discord 机器人,并试图让一个基本的响应系统运行起来。 Basically, I'm trying to make it look at words from two lists and only reply if it gets words from both lists.
基本上,我试图让它查看两个列表中的单词,并且仅在它从两个列表中获取单词时才回复。 Right now my code looks like this:
现在我的代码如下所示:
if any(word in msg for word in mean and bidoof):
await message.channel.send(random.choice(bidoof_angry))
I tried to use the "and" operator to take words from "mean" and "bidoof" but it's acting almost like I feel "or" should.我尝试使用“and”运算符从“mean”和“bidoof”中获取单词,但它的行为几乎就像我觉得“或”应该的那样。 It replies when it sees a word from the "bidoof" list, even if there are no words form the other list in the message.
当它从“bidoof”列表中看到一个词时,它会回复,即使消息中没有来自另一个列表的词。 I'm very new to this, so any help is greatly appreciated.
我对此很陌生,因此非常感谢任何帮助。
It's simple.这很简单。 Just use the AND operator.
只需使用 AND 运算符。
if any(word in msg for word in mean) and bidoof:
await message.channel.send(random.choice(bidoof_angry))
The upper code should work if you mean to check if bidoof is True.如果您要检查 bidoof 是否为 True,上面的代码应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.