简体   繁体   English

Reset_cooldown Discord.py

[英]Reset_cooldown Discord.py

Im pretty new to discord.py, and python in general but im trying to learn.我对discord.py和python很陌生,但我正在努力学习。 I dont know how to add the command.reset_cooldown to my code.我不知道如何将 command.reset_cooldown 添加到我的代码中。 As it says in the code below, i want !test to ignore the cooldown but i want !test 2 to have the cooldown.正如它在下面的代码中所说,我希望 !test 忽略冷却时间,但我希望 !test 2 有冷却时间。 Can someone help me?有人能帮我吗?

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

Essentially, exactly what the guy above said, but without the await .本质上,正是上面那个人所说的,但没有await Tried the his code and it didn't work, luckily I was able to find sources that pointed me in the right directions.尝试了他的代码,但没有奏效,幸运的是我能够找到为我指明正确方向的来源。

@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) will reset the cooldown for the user that invoked the command. 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')
        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')

For future reference and new readers, the Discord.py Extensions (discord.etx) do this differently and is stated in the 1.4 documentary.为了将来参考和新读者,Discord.py 扩展 (discord.etx) 以不同方式执行此操作,并在 1.4 纪录片中进行了说明。
Instead of calling reset_cooldown on the function, you call it on the Command object, which is from Context ( ctx.command ).而不是调用的reset_cooldown的功能,你叫它的Command对象,它是从Contextctx.command )。
Source: discord.ext.commands.Command.reset_cooldown来源: discord.ext.commands.Command.reset_cooldown

I had to find this out myself too, since my cooldown function returns at points where a cooldown of five minutes is not deserved.我也必须自己找出来,因为我的冷却时间函数会在不值得冷却 5 分钟的地方返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM