本文介紹了discord.py 中的命令冷卻時間的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我希望我的 discord 機器人的命令有冷卻時間.我嘗試了其他方法,但它們似乎都不適用于我所擁有的.
I want commands for my discord bot to have cooldowns. I've tried other methods, but none of them seemed to work for what I have.
@client.event
async def on_message(message):
if message.content == 'shear sheep':
await message.channel.send('you sheared your sheep, gaining 1 wool.')
#cooldown?
推薦答案
我建議使用變量來跟蹤使用該命令或冷卻前的天氣.
I would suggest using a variable to track weather the command has been used or before the cooldown.
import time
cooldown = True
@client.event
async def on_message(message):
global cooldown
if message.content == 'shear sheep' and cooldown:
cooldown = False
await message.channel.send('you sheared your sheep, gaining 1 wool.')
time.sleep(1)
cooldown = True
這將為所有用戶添加冷卻時間,如果您想為每個用戶添加冷卻時間,請使用表格檢查單個用戶是否使用過該命令的天氣.
This will add a cooldown for all users, if you want to add a cooldown for each user, use a table to check weather if an individual user has used the command.
import time
cooldown = []
@client.event
async def on_message(message):
global cooldown
if message.content == 'shear sheep' and cooldown.count(message.author.id) == 0:
cooldown.append(message.author.id)
await message.channel.send('you sheared your sheep, gaining 1 wool.')
time.sleep(1)
cooldown.remove(message.author.id)
這篇關于discord.py 中的命令冷卻時間的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!