简体   繁体   English

当两个条件都满足时,如何使 Discord Bot 响应?

[英]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.

相关问题 当我使用函数获取前缀时,如何让我的 Discord 机器人同时响应自定义前缀和提及? - How to make my Discord bot respond to both custom prefixes and mentions when I use a function to get the prefix? 输入冷却时间 (discord.py) 时如何让机器人做出响应? - How to make the bot respond when typing in a cooldown (discord.py)? 当特定用户在频道中发送消息时,如何让我的 discord 机器人响应? - How do I make my discord bot respond when a specific user sends a message in the channel? 如何让我的不和谐机器人响应正确答案? - How can I make my discord bot respond to the correct answer? Discord.py 如何让机器人不响应 PM - Discord.py How to make bot not respond to PM's 你如何让一个不和谐的机器人响应来回? - How do you make a discord bot respond to a back-and-forth? 如何让 discord 机器人在没有命令的情况下做出响应(但在 python 中)? - How do you make a discord bot respond without commands (but in python)? 如何使 discord 机器人响应具有不同图像/响应的命令? - How to make a discord bot respond to a command with different images/responses? 如何让 Discord 机器人响应 DM 中的命令? (Python) - How do you make a Discord bot respond to commands in DMs? (Python) 如何使 discord 机器人响应其他消息中的不同(多个)关键字? - How to make the discord bot respond different (multiple) keywords in the others message?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM