python - 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 类型忽略了冷却谓词。有没有办法将其应用于它?
解决方案
我认为没有办法做到这一点,因为内置的冷却时间可以与命令框架一起使用,这就引出了一个问题,为什么你要从(更好的)命令框架改为仅 on_message?无论如何,您可能必须使用自己的冷却系统,这不应该太难制作。你只需要一个用户的字典:可能是最后一次使用。
推荐阅读
- python - 将字符串转换为十六进制并在 Python 中通过串行发送
- java - 递归问题的测试用例中的错误
- assembly - 优化第 7 代英特尔酷睿视频 RAM 中的递增 ASCII 十进制计数器
- python - 如何使用 inspectdb 命令从 oracle 表同义词创建 Django 模型
- java - Spring execption:org.hibernate.tool.schema.spi.CommandAcceptanceException: Error execution DDL "create table post
- fluentd - FluentD 配置以索引弹性日志中的所有字段
- discord.js - 我有一个 watch.json 文件,但它不会忽略文件夹
- c# - 使用 VS 2019 调试 Xamarin.Forms 项目引用的 dll
- c# - 如何从 C# 将日志插入 Oracle SQL?
- python - Python - 在Windows10中打开文件的路径中用\\替换/