<bdo id='pJdZj'></bdo><ul id='pJdZj'></ul>
  • <legend id='pJdZj'><style id='pJdZj'><dir id='pJdZj'><q id='pJdZj'></q></dir></style></legend>
    1. <small id='pJdZj'></small><noframes id='pJdZj'>

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

      <tfoot id='pJdZj'></tfoot>

        Discord.py 每个用户的冷却时间不同

        时间:2023-09-09
        • <legend id='WYICH'><style id='WYICH'><dir id='WYICH'><q id='WYICH'></q></dir></style></legend>

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

                  <tfoot id='WYICH'></tfoot>

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

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

                  问题描述

                  如果用户不在列表中,我想创建一个只有冷却时间的命令这是我的代码:

                  I want to make a command that have only a cooldown if the user is not in a list This is my code:

                  @commands.command(name='cooldown')
                  @commands.cooldown(1, 300, commands.BucketType.user)
                  async def cdown(self, ctx):
                    await ctx.send("Executed")
                  

                  应该是这样的:

                  @commands.command(name='cooldown')
                  if not user in no_cooldown_users:
                    @commands.cooldown(1, 300, commands.BucketType.user)
                  async def cdown(self, ctx):
                    await ctx.send("Executed")
                  

                  有没有可能做这个而不是使用配置?

                  Is there any possibility to make this instead of using a config?

                  推荐答案

                  你要自定义冷却时间,这里举个很简单的例子

                  You have to make a custom cooldown, here a very simple example

                  from discord.ext import commands
                  
                  class CustomCooldown:
                      def __init__(self, rate, per, alter_rate, alter_per, bucket, *, elements):
                          self.elements = elements
                          # Default mapping is the default cooldown
                          self.default_mapping = commands.CooldownMapping.from_cooldown(rate, per, bucket)
                          # Alter mapping is the alternative cooldown
                          self.alter_mapping = commands.CooldownMapping.from_cooldown(alter_rate, alter_per, bucket)
                          # Copy of the original BucketType
                          self._bucket_type = bucket
                  
                      def __call__(self, ctx):
                          key = self.alter_mapping._bucket_key(ctx.message)
                  
                          if self._bucket_type is commands.BucketType.member: # `BucketType.member` returns a tuple
                              key = key[1] # The second (last) value is the member ID, the first one is the guild ID
                  
                          if key in self.elements:
                              # If the key is in the elements, the bucket will be taken from the alternative cooldown
                              bucket = self.alter_mapping.get_bucket(ctx.message)
                          else:
                              # If not, from the default cooldown
                              bucket = self.default_mapping.get_bucket(ctx.message)
                  
                          # Getting the ratelimit left (can be None)
                          retry_after = bucket.update_rate_limit()
                  
                          if retry_after: # If the command is on cooldown, raising the error
                              raise commands.CommandOnCooldown(bucket, retry_after)
                          return True
                  

                  使用它:

                  @command.commands()
                  @commands.check(CustomCooldown(1, 300, 1, 0, commands.BucketType.user, elements=[list of ids]))
                  async def foo(self, ctx):
                      ...
                  

                  前两个值是默认冷却时间的速率和时间,接下来的两个值是特殊"冷却时间.冷却.接下来是桶类型,最后是元素列表(id).

                  The first two values are the rate and per of the default cooldown, the next two values are for the "special" cooldown. Next there's the bucket type, and lastly the list of elements (ids).

                  您还可以使用此方法为每个角色/公会/类别/频道提供不同的冷却时间...

                  You can also use this method for different cooldown per roles/guilds/categories/channels...

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

                  上一篇:不和谐.py |为某人添加角色 下一篇:删除“找不到命令"错误 discord.py

                  相关文章

                  最新文章

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

                    <legend id='1Rm9g'><style id='1Rm9g'><dir id='1Rm9g'><q id='1Rm9g'></q></dir></style></legend>

                      • <bdo id='1Rm9g'></bdo><ul id='1Rm9g'></ul>

                      <small id='1Rm9g'></small><noframes id='1Rm9g'>