python - 在不和谐消息中搜索多个关键字?不和谐.py 机器人

标签 python bots discord discord.py

所以正在开发一个简单的不和谐机器人。除了一件小事之外,我一切都工作正常。我有一些针对不同关键字的机器人回复。然而,我想用多个关键字触发一个机器人响应。 ATM 我为每个关键字写了相同的代码。有没有办法压缩这个?

if 'SERVER' in message.content.upper():
    await bot.send_message(channel, 'For all Ark Server details type: **nB.arkserver**')
if 'TAMING' in message.content.upper():
    await bot.send_message(channel, 'For all Ark Server details type: **nB.arkserver**')
if 'GATHER' in message.content.upper():
    await bot.send_message(channel, 'For all Ark Server details type: **nB.arkserver**')

最佳答案

是的,欢迎来到社区

if any([keyword in message.content.upper() for keyword in ('SERVER', 'TAMING', 'GATHER')]):
    await bot.send_message(channel, 'For all Ark Server details type: **nB.arkserver**')

关于python - 在不和谐消息中搜索多个关键字?不和谐.py 机器人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54734757/

相关文章:

python - VS 代码调试器立即退出

javascript - Replit Discord 机器人不断关闭

python - Discord py bot 未触发 on_member_join 函数

python - 如何在 heroku 上托管我的 discord.py 机器人?

python - 检查已加入 channel 的特定用户

python - 运行时钟和触发

python - 如何删除小部件

python - 在 Windows 上安装 pycurl 时,我得到 "Please specify --curl-dir=/path/to/built/libcurl"

c# - 如何在 MessageController.cs Post 方法中使用 PromptDialog.Confirm()

python - 在 Selenium Python 绑定(bind)中设置页面加载超时