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


Smart猫小萌
浏览 151回答 3
3回答

qq_笑_17

@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')        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')        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我也必须自己找出答案,因为我的冷却功能会在不值得冷却五分钟的地方返回。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python