亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 149 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號