简体   繁体   中英

Discord.py - Apply cooldown to .event on_message

I'm looking to apply a cooldown to on_message. I've moved from running a command with a preface (such as.claim 000) to simple '000' or whatever code on DM.

Old code:

@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)

New code:

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

However the new.event type ignores the cooldown predicate. Is there a way to apply this to it?

I don't think there's a way to do this, as the builtin cooldowns were made to work with the commands framework, which begs the question why are you changing from the (better) framework for commands to on_message only? Regardless, you'd probably have to use your own cooldown system, which shouldn't be too hard to make. You'll just want a dict of user: last use probably.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM