python - 在执行命令时检查用户命令
问题描述
你是怎么做到的,如果有人使用命令,如果用户在给定时间内回答,计时器就会启动并执行某些操作?就像有人做“!shoot @user#0000”一样,被标记的用户必须在 10 秒内回答“!dodge”,否则他会死
解决方案
您可以使用以下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!")
推荐阅读
- python-3.x - 根据某些条件在熊猫中填充一列的逻辑
- xaml - 滚动时保持 ListView.Header 锚定/粘性/冻结到顶部
- php - 为什么我在安装 32 KB 模块时遇到 composer 内存错误?
- android - Android Paging 3 库 - 用于从 Room 数据库中分页数据,数据更改时流变为空
- laravel - Laravel getAttribute() 就雄辩?
- python - 静态文本上的 wxPython 自定义绘制事件擦除静态文本标签
- python - Python remove everything after specific string and loop through all rows in multiple columns in a dataframe
- c# - Alternative to traits
- java - command "mvn spring-boot:run" does not take changes at run in other modules than main module?
- c++ - 构造函数的成员初始化列表不能包含超类的成员?