【发布时间】:2021-05-14 01:01:31
【问题描述】:
根据给定的提示(消息 1),用户应该能够向左、向右或保持不动做出响应,并且不和谐机器人将提供自定义消息(消息 2-4 之一)。我试图创建多个检查来检测不同的用户响应,但无济于事。我在网上找了其他解决方案,其中一些提到了使用asyncio,但我对它不是太熟悉,即使使用它也无法解决问题。任何帮助表示赞赏,我对python相当陌生。谢谢。
代码如下:
if message.content.startswith('gametest'):
channel = message.channel
await channel.send('Would you like to play?')
def check(m):
return m.content == 'yes' and m.channel == channel
msg = await client.wait_for('message', check=check)
await channel.send('Message1')
def check2(m):
return m.content == 'left' and m.channel == channel
def check3(m):
return m.content == 'right' and m.channel == channel
def check4(m):
return m.content == 'stay still' and m.channel == channel
msg2 = await client.wait_for('message', timeout=30.0, check=check2)
await channel.send('Message2')
msg3 = await client.wait_for('message', timeout=30.0, check=check3)
await channel.send('Message3')
msg4 = await client.wait_for('message', timeout=30.0, check=check4)
await channel.send('Message4')
【问题讨论】:
标签: python python-3.x async-await discord discord.py