重置冷却时间Discord.py

2024-06-16 08:32:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我对discord.py和python都是新手,但我正在努力学习。我不知道如何将command.reset\u 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')
    elif command.lower() == '2':
        await ctx.send('I want this to have a Cooldown')```

Tags: to代码pynonesendawaitthiscommand
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。尝试了his代码,但没有成功,幸运的是,我能够找到指向正确方向的源代码

@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对象调用它,该对象来自Contextctx.command)。
资料来源:discord.ext.commands.Command.reset_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)将重置调用该命令的用户的冷却时间

相关问题 更多 >