discord.py重写|仅允许一个命令实例 [英] discord.py rewrite | Allow only one instance of a command

查看:29
本文介绍了discord.py重写|仅允许一个命令实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用我的机器人时,我发现多个人可以同时使用同一命令.由于它的性质,我只希望一次执行一个命令.

Whilst using my bot, I discovered that multiple people can use the same command simultaneously. I would only like the command to be ran one at a time, due to it's nature.

是否有一种方法可以确保仅运行该命令的一个实例?如果有,请告诉我.我需要这种固定的方法,所以我们将不胜感激.

Is there a way to ensure there is only one instance of the command running? If there is, please tell me. I need this fixed sort of quickly, so any help is appreciated.

推荐答案

您可以对所有超时时间较长的用户进行冷却,然后在命令末尾重置冷却时间:

You can have a cooldown for all users with some large timeout, then reset the cooldown at the end of the command:

from discord.ext.commands import cooldown

@bot.command()
@cooldown(1, 1000)  # 1000 second cooldown
async def comm(ctx):
    ...
    comm.reset_cooldown(ctx)

这篇关于discord.py重写|仅允许一个命令实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆