Limitieren von Commands in Discord
Verfasst: Mittwoch 20. Januar 2021, 02:19
Ich versuche gerade ein command auf verschiedene Rollen zu limitieren. Das heisst falls eine bestimme Rolle bzw "Member" den command <?test> 5 mal braucht dann wird dieser auf ein Cooldown gesetzt von zb 30 Sekunden. Danach wird die Limitierung wieder zurück gesetzt. Ich versteh nur nicht ganz wie kann ich dass ganze auf eine Rolle zuweisen dass ich es parallel auf verschiedene rollen eine Wirkung hat. Und ist es möglich die Zeit des timers bzw die Sekunden im bestimmten moment gerade heraus zu bekommen. Weil in Zukunft sollte der delay bei 4h liegen und dann wäre es ziemlich nützlich zu wissen wie lange noch der cooldown da steht.
Mein code:
import threading
import time
bot = commands.Bot(command_prefix = '?', help_command=None)
def reset():
global limit
print("Limit has been reset")
limit = 0
@bot.command()
async def test(context):
global limit
print(limit)
if limit < 3:
limit = limit + 1
print("command used: " + str(limit) + " times!")
if limit == 3:
await context.send("Limit is reached")
t = threading.Timer(5.0, reset)
t.start()
print(str(threading.time()))
await context.send("command used: " + str(limit) + " times!")
else:
print("command used: " + str(limit) + " times!")
await context.send("Your limit has been reach")
Ich bedanke mich für jede hilf!
Mein code:
import threading
import time
bot = commands.Bot(command_prefix = '?', help_command=None)
def reset():
global limit
print("Limit has been reset")
limit = 0
@bot.command()
async def test(context):
global limit
print(limit)
if limit < 3:
limit = limit + 1
print("command used: " + str(limit) + " times!")
if limit == 3:
await context.send("Limit is reached")
t = threading.Timer(5.0, reset)
t.start()
print(str(threading.time()))
await context.send("command used: " + str(limit) + " times!")
else:
print("command used: " + str(limit) + " times!")
await context.send("Your limit has been reach")
Ich bedanke mich für jede hilf!