首页 > 解决方案 > 如何检查 message.content.lower 中的多个术语

问题描述

我正在编写一个机器人来阻止我的朋友玩联盟,但我想不出一种方法来检查消息中是否包含多个单词。

if 'league' in message.content.lower():
    response = random.choice(Response)
    await message.channel.send(response)

我在这里做的是复制粘贴并将league单词更改为另一个术语。我如何使它只有一行代码而不是整整 100 行?

标签: discord.py

解决方案


您可以使用以下any()功能:

some_words = ['word1', 'word2', 'word3']

if any(word in message.content.lower() for word in some_words):
    ...

推荐阅读