如果有人使用命令,计时器会启动,如果用户在给定时间内回答,计时器会执行某些操作,这是怎么做的?比如有人说"!shoot @user#0000“,被标记的用户必须在10秒内回答"!dodge”,否则他就会死。
发布于 2021-08-17 21:17:15
您可以使用wait_for method
@client.command(name = "shoot")
async def shoot_user(ctx, user: discord.Member):
channel = ctx.channel
def check(m):
return m.content == '!dodge' and m.channel == channel and m.author == user
try:
await client.wait_for('message', check=check, timeout = 10.0)
except asyncio.TimeoutError:
await channel.send(f"{user.mention} did not dodge in time!")
else:
await channel.send(f"{user.mention} dodged!")发布于 2021-08-17 21:06:01
我相信你需要多线程来结合计时功能。看看这篇文章。Python Equivalent of setInterval()?
https://stackoverflow.com/questions/68823979
复制相似问题