python - 如何为 A 或 B 制作 discord api 等待消息?
问题描述
我试图让我的代码获取用户输入,并且代码必须检查两个选项,但代码只注册第一个选项。
我尝试了不同的语法(content=('m!mode computer' or 'm!mode player'))
,但它们都不起作用。
async def AgainstWho():
global mode
await client.send_message(message.channel, content='Play against the computer or another player?\n')
mode = await client.wait_for_message(content=('m!mode computer' or 'm!mode player'))
if mode == 'm!mode computer':
mode = 1
if mode == 'm!mode player':
mode = 2
如果用户在m!mode player
代码中键入什么都不做,但m!mode computer
工作得很好。
解决方案
>>> 'm!mode computer' or 'm!mode player'
'm!mode computer'
这就是为什么。我假设这是 discord.py,根据文档,您想要的是:
mode = await client.wait_for_message(check=lambda m: return m.content.startswith('m!mode'))
之类的。
推荐阅读
- php - LARAVEL:在单个数组中添加键和值
- linux - 尝试在 bash linux 中使用“新行”命令复制语法
- sql - 如何转换列的值,如 ALL_TAB_COLUMNS 的 HIGH_VALUE 格式
- sql - 多值字段的值仅出现一次的 SQL 选择行
- electron - 将自定义页面/字段添加到使用电子生成器创建的 NSIS 设置
- python - 使用logstash将整个数据库保存到elasticsearch
- rally - 在 Rally 中,使用 Java REST API,如何获取 TestPlan 文件夹的所有子文件夹中存在的测试用例的完整列表?
- reactjs - 在 gitlab 运行器上使用 asar 构建的 React Electron 应用程序会创建 JavaScript 错误
- request - 如何将加密(3DES)数据发送到渡槽而不会出现任何错误?
- c# - C# 数据表,清除时获取 NullReferenceException