python - Discord py自动反应问题
问题描述
我的 discord.py 机器人中有一个事件,它应该只对包含“welc”或“welcome”的消息使用表情符号做出反应,但是,该机器人会对聊天中发送的所有消息做出反应。这是事件的代码。
@commands.Cog.listener()
async def on_message(self, message):
welcome1 = 'welcome'
welc = 'welc'
if message.content == welcome1 or welc:
await message.add_reaction('<:z_heart1:786021804690636810>')
我尝试在 if 语句中使用 else 传递,但这似乎不起作用。
解决方案
if message.content == welcome1 or welc:
是它破裂的地方。or welc
这意味着 ifwelc
不是 None 并且welc
不是 False。在这种情况下welc
,价值为welc
您可以使用我的示例中的列表来减少对 or 语句的需求。
@commands.Cog.listener()
async def on_message(self, message):
welcome1 = 'welcome'
welc = 'welc'
if message.content in [welcome1,welc]:
await message.add_reaction('<:z_heart1:786021804690636810>')
推荐阅读
- rust - 在 macOS 上安装 Rust 时如何修复“库未加载:@rpath/libssl.1.0.0.dylib”?
- azure - Azure B2C 自定义策略中的自定义角色声明
- performance - 如何找出执行 Xtensa 微处理器的特定指令(例如 wsr / rsr)所需的时间?
- here-api - 我可以使用地理编码器发出 GET 请求以按多个 ID 列出多个城市吗?
- gulp - 意外错误:在循环内多次执行 Gulp.js 任务时编写回调调用
- tensorflow - 如何在tensorflow keras中访问自定义层的递归层
- c# - winforms程序内的XAML窗口
- c# - Include 属性 lambda 表达式 [...] 无效。表达式应表示属性访问
- android - Wowza.GoCoder 不能与 org.bytedeco.javacv.FFmpegFrameRecorder 一起使用
- excel - VBA代码将带有颜色的单元格复制到同一工作表中的不同单元格