• <tfoot id='BMlWH'></tfoot>
  • <legend id='BMlWH'><style id='BMlWH'><dir id='BMlWH'><q id='BMlWH'></q></dir></style></legend>

    <small id='BMlWH'></small><noframes id='BMlWH'>

      <i id='BMlWH'><tr id='BMlWH'><dt id='BMlWH'><q id='BMlWH'><span id='BMlWH'><b id='BMlWH'><form id='BMlWH'><ins id='BMlWH'></ins><ul id='BMlWH'></ul><sub id='BMlWH'></sub></form><legend id='BMlWH'></legend><bdo id='BMlWH'><pre id='BMlWH'><center id='BMlWH'></center></pre></bdo></b><th id='BMlWH'></th></span></q></dt></tr></i><div id='BMlWH'><tfoot id='BMlWH'></tfoot><dl id='BMlWH'><fieldset id='BMlWH'></fieldset></dl></div>

        • <bdo id='BMlWH'></bdo><ul id='BMlWH'></ul>

        discord.py 中 on_message 的冷却时间

        时间:2023-09-09
      1. <legend id='ZsoTU'><style id='ZsoTU'><dir id='ZsoTU'><q id='ZsoTU'></q></dir></style></legend>
          <bdo id='ZsoTU'></bdo><ul id='ZsoTU'></ul>

            <tbody id='ZsoTU'></tbody>
            <tfoot id='ZsoTU'></tfoot>
            <i id='ZsoTU'><tr id='ZsoTU'><dt id='ZsoTU'><q id='ZsoTU'><span id='ZsoTU'><b id='ZsoTU'><form id='ZsoTU'><ins id='ZsoTU'></ins><ul id='ZsoTU'></ul><sub id='ZsoTU'></sub></form><legend id='ZsoTU'></legend><bdo id='ZsoTU'><pre id='ZsoTU'><center id='ZsoTU'></center></pre></bdo></b><th id='ZsoTU'></th></span></q></dt></tr></i><div id='ZsoTU'><tfoot id='ZsoTU'></tfoot><dl id='ZsoTU'><fieldset id='ZsoTU'></fieldset></dl></div>
          • <small id='ZsoTU'></small><noframes id='ZsoTU'>

                  本文介绍了discord.py 中 on_message 的冷却时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我已经制作了一个练级系统,但我不知道在on_message中制作一个冷却我想添加一个 BucketType.member 冷却时间,并且因为我使用 MondoDB 作为数据库,所以我无法存储他们最后一次发送消息的时间,而是我正在寻找 on_message 的冷却时间 的作用类似于命令冷却,因此它可以自动执行任何操作
                  这是目前的代码

                  I have made a Leveling system but i can't figure out to make a cooldown in on_message i want to add a BucketType.member cooldown and as im using MondoDB for database so i can't afford to store the last time they send message instead im looking for a cooldown for on_message which works similar to commands cooldown so it can automatically take any action
                  This is the code so far

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

                  推荐答案

                  您应该使用 CooldownMapping.from_cooldownon_message 事件添加冷却时间,例如:

                  You should use CooldownMapping.from_cooldown to add cooldowns to the on_message event, example:

                  import typing
                  import discord
                  from discord.ext import commands
                  
                  class SomeCog(commands.Cog):
                      def __init__(self, bot):
                          self.bot = bot
                          self._cd = commands.CooldownMapping.from_cooldown(1, 6.0, commands.BucketType.member) # Change accordingly
                                                                          # rate, per, BucketType
                  
                      def get_ratelimit(self, message: discord.Message) -> typing.Optional[int]:
                          """Returns the ratelimit left"""
                          bucket = self._cd.get_bucket(message)
                          return bucket.update_rate_limit()
                  
                  
                      @commands.Cog.listener()
                      async def on_message(self, message):
                          if "check something":
                              # Getting the ratelimit left
                              ratelimit = self.get_ratelimit(message)
                              if ratelimit is None:
                                  # The user is not ratelimited, you can add the XP or level up the user here
                  
                              else:
                                  # The user is ratelimited
                  

                  这篇关于discord.py 中 on_message 的冷却时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Discord bot 检查用户是否为管理员 下一篇:(discord.py) 获取特定语音频道中所有成员的列表

                  相关文章

                  最新文章

                  <i id='OAoOo'><tr id='OAoOo'><dt id='OAoOo'><q id='OAoOo'><span id='OAoOo'><b id='OAoOo'><form id='OAoOo'><ins id='OAoOo'></ins><ul id='OAoOo'></ul><sub id='OAoOo'></sub></form><legend id='OAoOo'></legend><bdo id='OAoOo'><pre id='OAoOo'><center id='OAoOo'></center></pre></bdo></b><th id='OAoOo'></th></span></q></dt></tr></i><div id='OAoOo'><tfoot id='OAoOo'></tfoot><dl id='OAoOo'><fieldset id='OAoOo'></fieldset></dl></div>

                      • <bdo id='OAoOo'></bdo><ul id='OAoOo'></ul>

                      <tfoot id='OAoOo'></tfoot><legend id='OAoOo'><style id='OAoOo'><dir id='OAoOo'><q id='OAoOo'></q></dir></style></legend>
                    1. <small id='OAoOo'></small><noframes id='OAoOo'>