首页 > 解决方案 > 在执行命令时检查用户命令

问题描述

你是怎么做到的,如果有人使用命令,如果用户在给定时间内回答,计时器就会启动并执行某些操作?就像有人做“!shoot @user#0000”一样,被标记的用户必须在 10 秒内回答“!dodge”,否则他会死

标签: pythondiscord.py

解决方案


您可以使用以下wait_for 方法

@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!")


推荐阅读