discord.py - 如何检查 message.content.lower 中的多个术语
问题描述
我正在编写一个机器人来阻止我的朋友玩联盟,但我想不出一种方法来检查消息中是否包含多个单词。
if 'league' in message.content.lower():
response = random.choice(Response)
await message.channel.send(response)
我在这里做的是复制粘贴并将league
单词更改为另一个术语。我如何使它只有一行代码而不是整整 100 行?
解决方案
您可以使用以下any()
功能:
some_words = ['word1', 'word2', 'word3']
if any(word in message.content.lower() for word in some_words):
...
推荐阅读
- firebase - Firebase 实时数据库规则“未知变量‘请求’。”
- r - R 使用组合与应用
- django - 如何在 Django 中制作和使用自定义模板加载器
- sql - SQL 错误 [IX000]:在查询的任何表中都找不到列 (t)(或 SLV 未定义)
- plsql - 在循环中插入多个值
- r - 向 ggtree 图添加图例
- javascript - 使用 jquery addClass()/removeClass() 更改默认行为
- terraform - 用于 aws 提供程序的 Terraform 无效 arn
- javascript - 如何构建与溢出一起使用的可调整大小的 DIV:自动?
- javascript - TypeError: fs.readdirSync 不是 React js 的函数