【发布时间】:2021-10-15 13:00:51
【问题描述】:
我正在尝试编写一个不和谐的机器人,它对每个用户执行相同的命令具有不同的冷却时间。例如,当用户 1 !work 时,他们的冷却时间是 5 秒,而用户 2 在他们 !work 时有 6 秒的冷却时间。阅读冷却装饰器的文档,似乎没有办法拥有多个冷却时间。此方法不起作用,因为我收到一个错误,因为 ctx 尚未定义,并且我无法在函数定义之前获取用户数据。我将如何设置它以便我可以为每个用户设置可变的冷却时间?
def fetch(self, username, column):
self.cur.execute("SELECT %s FROM users WHERE username=?" %column, (username,))
rows = self.cur.fetchall()
return rows
#the call to fetch should theoretically return the cooldown for that user
@commands.cooldown(rate=1, per=fetch(str(ctx.message.author), cooldown), type=commands.BucketType.user)
@bot.command(name='example')
async def example(ctx):
await ctx.send("hello")
【问题讨论】:
-
顺便说一句
per应该是float -
这能回答你的问题吗? Discord.py different cooldown per user
标签: python discord discord.py