discord.py-rewrite - 如何覆盖和更改某些用户的冷却时间?
discord.py-rewrite - How to overwrite and change cooldown for certain users?
由于我之前的post被锁定了,所以我决定这次我想要的东西更简洁一些。所以我有一个不和谐的机器人,用 Python (3) 编写,我想用基于用户的冷却来装饰我的所有命令,以防止潜在的滥用。但是,我希望机器人开发人员完全绕过这个冷却时间,如果可能的话,我希望如果命令调用者在特定的 id 列表中,覆盖他的冷却时间(这样他只需要等待 3 秒而不是 5 秒例如)。我试过这个:
class Bot(commands.Bot):
class Cooldown:
def __init__(self, rate=1, per=3.0, ctype=commands.BucketType.user):
self.rate = rate
self.per = float(per)
self.ctype = ctype
self.cmd_cldwn = commands.cooldown(rate, per, ctype)
def __call__(self):
def pred(ctx):
if ctx.author.id in bot_developers:
return True
ctx = self.cmd_cldwn(ctx)
return commands.Command.is_on_cooldown(self, ctx)
return commands.check(pred)
但是我不知道怎么用。有人可以帮我吗?
我实际上找到了解决方案,方法是创建 CooldownMapping
class。
由于我之前的post被锁定了,所以我决定这次我想要的东西更简洁一些。所以我有一个不和谐的机器人,用 Python (3) 编写,我想用基于用户的冷却来装饰我的所有命令,以防止潜在的滥用。但是,我希望机器人开发人员完全绕过这个冷却时间,如果可能的话,我希望如果命令调用者在特定的 id 列表中,覆盖他的冷却时间(这样他只需要等待 3 秒而不是 5 秒例如)。我试过这个:
class Bot(commands.Bot):
class Cooldown:
def __init__(self, rate=1, per=3.0, ctype=commands.BucketType.user):
self.rate = rate
self.per = float(per)
self.ctype = ctype
self.cmd_cldwn = commands.cooldown(rate, per, ctype)
def __call__(self):
def pred(ctx):
if ctx.author.id in bot_developers:
return True
ctx = self.cmd_cldwn(ctx)
return commands.Command.is_on_cooldown(self, ctx)
return commands.check(pred)
但是我不知道怎么用。有人可以帮我吗?
我实际上找到了解决方案,方法是创建 CooldownMapping
class。