首页 > 解决方案 > Discord.py - 对 .event on_message 应用冷却时间

问题描述

我正在寻找对 on_message 应用冷却时间。我已经从运行带有前言(例如 .claim 000)的命令转变为简单的“000”或 DM 上的任何代码。

旧代码:

@commands.command(name='claim',pass_context=True)   
@commands.cooldown(1, 5, commands.BucketType.user)
    async def redeem(self, ctx, code):
        if isinstance(ctx.channel, discord.channel.DMChannel)

新代码:

@bot.event
@bot.cooldown(1, 5, commands.BucketType.user)
async def on_message(message):

然而,新的 .event 类型忽略了冷却谓词。有没有办法将其应用于它?

标签: pythondiscord

解决方案


我认为没有办法做到这一点,因为内置的冷却时间可以与命令框架一起使用,这就引出了一个问题,为什么你要从(更好的)命令框架改为仅 on_message?无论如何,您可能必须使用自己的冷却系统,这不应该太难制作。你只需要一个用户的字典:可能是最后一次使用。


推荐阅读