【问题标题】:Discord.py - Apply cooldown to .event on_messageDiscord.py - 对 .event on_message 应用冷却时间
【发布时间】:2021-03-25 12:29:35
【问题描述】:

我希望对 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 类型忽略了冷却谓词。有没有办法将其应用于它?

【问题讨论】:

    标签: python discord


    【解决方案1】:

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

    【讨论】:

    • 用于通过 DM 将代码兑换给机器人。我认为能够用代码回复它而不是输入命令是一种更好的用户体验。
    猜你喜欢
    • 2021-05-02
    • 2022-01-16
    • 1970-01-01
    • 2018-10-21
    • 2021-05-15
    • 2020-10-14
    • 1970-01-01
    • 2021-04-21
    相关资源
    最近更新 更多