我正在编写一个机器人来检查每个用户在我的服务器中发送的每条消息,并将 XP 添加到一个文件中。我已经编写了执行此操作的函数,但我想添加反垃圾邮件,其中机器人每 10 秒(基本上是 10 秒的冷却时间)才记录一次消息。有人可以帮忙吗? (编辑:冷却时间必须是每个用户)
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if checkUser(message.author.id) == True:
add = gcSPM(message.author.id)
balancePlus(message.author.id, int(add))
await bot.process_commands(message)
答案 0 :(得分:0)
你可以做到
from discord.ext import commands
@commands.cooldown(1, 10, commands.BucketType.guild)
...
请注意,我使用的是 commands
库。不要使用 on_message
来处理命令。有一个完整的库:https://discordpy.readthedocs.io/en/latest/ext/commands/api.html