首页 > 解决方案 > 如何为 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工作得很好。

标签: pythondiscorddiscord.py

解决方案


>>> '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'))

之类的。


推荐阅读