【发布时间】:2021-01-07 07:50:10
【问题描述】:
我目前正在使用
@commands.cooldown(1, 60, bucket)
Discord.py 命令的装饰器,这部分工作。假设我有两个单独的函数:func_a() 和 func_b()。我需要它,所以当用户调用 func_a() 或 func_b() 时,冷却时间会同时应用于两者。
示例:用户调用func_a(),用户等待 10 秒,但冷却时间为 60 秒。用户调用func_b(),机器人回复“请等待 50 秒以使用此命令”
编辑: 使用下面的解决方案,对于那些想要黑名单(或白名单)功能的人,将代码更改为以下:
async def cog_check(self, ctx):
bucket = self._cd.get_bucket(ctx.message)
retry_after = bucket.update_rate_limit()
if ctx.author.id not in self.blacklist:
return True
else:
if retry_after:
# You're rate limited, send message here
await ctx.send(f"Please wait {round(retry_after)} seconds to use this command.")
return False
return True
【问题讨论】:
标签: discord.py python-decorators