Reset_cooldown Discord.py

Reset_cooldown Discord.py

我对 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')```
@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) 将为调用命令的用户重置冷却时间。

@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。尝试了他的代码但没有用,幸运的是我能够找到为我指明正确方向的资源。

@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,而是在 Command 对象上调用它,该对象来自 Context (ctx.command).
资料来源:discord.ext.commands.Command.reset_cooldown

我也必须自己找出这个问题,因为我的冷却功能 returns 在五分钟的冷却时间不值得的地方。