【问题标题】:Reset_cooldown Discord.pyReset_cooldown Discord.py
【发布时间】:2020-05-22 18:03:23
【问题描述】:

我对 discord.py 和 python 很陌生,但我正在努力学习。我不知道如何将 command.reset_cooldown 添加到我的代码中。正如它在下面的代码中所说,我希望 !test 忽略冷却时间,但我希望 !test 2 有冷却时间。有人可以帮我吗?

@commands.cooldown(1, 30, commands.BucketType.user)
async def test(ctx, command=None):
    if command is None:
        await ctx.send('I want this to ignore cooldown')
    elif command.lower() == '2':
        await ctx.send('I want this to have a Cooldown')```

【问题讨论】:

    标签: python python-3.x discord discord.py discord.py-rewrite


    【解决方案1】:
    @commands.cooldown(1, 30, commands.BucketType.user)
    async def test(ctx, command=None):
        if command is None:
            await ctx.send('I want this to ignore cooldown')
            ctx.command.reset_cooldown(ctx)  
            # reset_cooldown is an attribute of `Command`, not `function`
    
        elif command.lower() == '2':
            await ctx.send('I want this to have a Cooldown')
    

    为了将来的参考和新读者,Discord.py 扩展 (discord.etx) 以不同的方式执行此操作,并在 1.4 文档中进行了说明。
    不是在函数上调用reset_cooldown,而是在来自Context (ctx.command) 的Command 对象上调用它。
    来源:discord.ext.commands.Command.reset_cooldown

    我也必须自己找出答案,因为我的冷却功能会在不应该冷却五分钟的地方返回。

    【讨论】:

      【解决方案2】:
      @commands.cooldown(1, 30, commands.BucketType.user)
      async def test(ctx, command=None):
          if command is None:
              await ctx.send('I want this to ignore cooldown')
              test.reset_cooldown(ctx)
          elif command.lower() == '2':
              await ctx.send('I want this to have a Cooldown')
      

      await test.reset_cooldown(ctx) 将为调用该命令的用户重置冷却时间。

      【讨论】:

        【解决方案3】:
        @commands.cooldown(1, 30, commands.BucketType.user)
        async def test(ctx, command=None):
            if command is None:
                await ctx.send('I want this to ignore cooldown')
                test.reset_cooldown(ctx)
            elif command.lower() == '2':
                await ctx.send('I want this to have a Cooldown')
        

        基本上,正是上面那个人所说的,但没有await。尝试了他的代码,但它没有用,幸运的是我能够找到指向正确方向的资源。

        【讨论】:

          猜你喜欢
          • 2021-03-19
          • 2021-01-07
          • 2021-03-24
          • 2020-09-18
          • 2021-02-04
          • 2020-09-30
          • 2019-02-07
          • 2020-05-06
          • 2020-09-16
          相关资源
          最近更新 更多