为了账号安全,请及时绑定邮箱和手机立即绑定

Reset_cooldown Discord.py

Reset_cooldown Discord.py

Smart猫小萌 2022-07-19 20:57:19
我对 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')```
查看完整描述

3 回答

?
qq_笑_17

TA贡献1818条经验 获得超7个赞

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


查看完整回答
反对 回复 2022-07-19
?
料青山看我应如是

TA贡献1772条经验 获得超8个赞

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


查看完整回答
反对 回复 2022-07-19
?
四季花海

TA贡献1811条经验 获得超5个赞

@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


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


查看完整回答
反对 回复 2022-07-19
  • 3 回答
  • 0 关注
  • 150 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号