【发布时间】:2021-02-07 07:48:09
【问题描述】:
我正在 python 3.8.6 上制作 discord.py 机器人。
我希望这个特定的功能以特定的方式工作......
- 机器人发送嵌入
message = await ctx.send(embed=e) - 机器人将添加一个反应到嵌入
await message.add_reaction('✅') - 机器人将等待 30 秒,等待其他用户做出反应,并列出在 30 秒内做出反应的用户
- 继续执行其他命令
代码-
@bot.command()
async def command_name(ctx, function):
#code for function 1
#code for function 2
# making the embed
message = await ctx.send(embed=e)
await message.add_reaction('✅')
def check(reaction, user):
if user not in players and not user.bot:
players.append(user.mention)
return reaction.message == message and str(reaction.emoji) == '✅'
try:
await bot.wait_for('reaction_add', timeout=10, check=check)
except asyncio.TimeoutError:
await ctx.send('time is up, and not enough players')
else:
await ctx.send(players)
# further code
问题:机器人会立即发送玩家名单
问题:我可以添加什么让它等待 30 秒,将列表附加到对嵌入做出反应的用户,然后发送列表,如果 30 秒后 len(players) 不是 3 或更多发送 -
await ctx.send('time is up, and not enough players')
【问题讨论】:
标签: python async-await discord.py