Python discord.py中on_消息的冷却时间

Python discord.py中on_消息的冷却时间,python,discord,discord.py,Python,Discord,Discord.py,我制作了一个调平系统,但我不知道如何在on_消息中进行冷却 我想添加一个BucketType.member冷却时间,因为我使用MondoDB作为数据库,所以我无法存储他们上次发送消息的时间,而我正在寻找一个on_message的冷却时间,该冷却时间与命令冷却时间类似,因此它可以自动采取任何行动 这是目前为止的代码 @commands.Cog.listener() async def on_message(self , message): if message.channe

我制作了一个调平系统,但我不知道如何在
on_消息中进行冷却
我想添加一个
BucketType.member
冷却时间,因为我使用MondoDB作为数据库,所以我无法存储他们上次发送消息的时间,而我正在寻找一个
on_message
的冷却时间,该冷却时间与命令冷却时间类似,因此它可以自动采取任何行动
这是目前为止的代码

@commands.Cog.listener()
    async def on_message(self , message):
        if message.channel.id in talk_channels:
            stats = leveling.find_one({"id":message.author.id})
            if not message.author.bot:
                if stats is None:
                    new_user = {"id" : message.author.id, "xp" : 0}
                    leveling.insert_one(new_user)
                else:
                    
                    xp = stats["xp"] + 5
                    leveling.update_one({"id" : message.author.id}, {"$set" : {"xp" : xp}})
                    lvl = 0
                    while True:
                        if xp < ((50*(lvl**2))+(50*lvl)):
                            break
                        lvl += 1
                    xp -= ((50*((lvl-1)**2))+(50*(lvl-1)))
                    if xp == 0:
                        await message.channel.send(f"Congo you leveled up {message.author.mention} to **level: {lvl}**")
                        for i in range(len(level_role)):
                            if lvl == levelnum[i]:
                                await message.author.add_roles(discord.utils.get(message.author.guild.roles, name=level_role[i]))
                                embed = discord.Embed(title="LEVEL UP", description=f"You have reached a mile stone of {lvl} and has got role **{level_role[i]}**", color=0x00ffff)
                                embed.set_thumbnail(url=message.author.avatar_url)
                                await message.channel.send(embed=embed)

@commands.Cog.listener()
_消息上的异步定义(self,message):
如果对话频道中的message.channel.id:
stats=leveling.find_one({“id”:message.author.id})
如果不是message.author.bot:
如果stats为None:
新用户={“id”:message.author.id,“xp”:0}
找平。插入一个(新用户)
其他:
xp=统计数据[“xp”]+5
leveling.update_one({“id”:message.author.id},{“$set”:{“xp”:xp})
lvl=0
尽管如此:
如果xp<((50*级**2))+(50*级)):
打破
lvl+=1
xp-=((50*((1级)**2))+(50*(1级)))
如果xp==0:
wait message.channel.send(f“您将{message.author.notice}升级到**级别:{lvl}**”)
对于范围内的i(len(级别_角色)):
如果lvl==levelnum[i]:
等待message.author.add_角色(discord.utils.get(message.author.guild.roles,name=level_角色[i]))
embed=discord.embed(title=“LEVEL UP”,description=f“您已经到达了{lvl}的里程碑,并且获得了角色**{LEVEL_role[i]}**”,color=0x00ffff)
嵌入.set_缩略图(url=message.author.avatar_url)
等待message.channel.send(嵌入=嵌入)

您应该使用
冷却映射。从\u cooldown
on\u消息事件添加冷却,例如:

导入键入
进口不和
从discord.ext导入命令
类SomeCog(commands.Cog):
def uuu init uuuu(自我,机器人):
self.bot=bot
self._cd=commands.CooldownMapping.from_cooldown(1,6.0,commands.BucketType.member)#相应地更改
#价格,每件,布基类型
def get_ratelimit(self,message:discord.message)->键入。可选[int]:
“”“返回剩余的费率限制”“”
bucket=self.\u cd.get\u bucket(消息)
返回bucket.update\u rate\u limit()
@commands.Cog.listener()
_消息上的异步定义(self,message):
如果“检查某物”:
#让税率限制保持不变
ratelimit=self.get\u ratelimit(消息)
如果费率限制为“无”:
#用户不受费率限制,您可以在此处添加XP或升级用户
其他:
#用户受费率限制

非常感谢你,兄弟,我只需要同样的东西