Answer the question
In order to leave comments, you need to log in
How do I make a command in discord.py usable once per hour/day/year?
Here is the command
@client.command()
async def beg(ctx):
denga = random.randint(0,100)
user = ctx.author
hour=None
mbalance=collection.find_one({"_id":user.id})["balance"]
if hour==None:
collection.update_one({"_id":user.id},
{"$set": {"balance":mbalance+denga }})
await ctx.send(embed=discord.Embed(
description=f'**Копошась на полу вы нашли {denga} монет**'))
else:
await ctx.send("Вы можете использовать эту команду лишь раз в час!")
Answer the question
In order to leave comments, you need to log in
Use a decorator
@commands.cooldown(rate, per, type=<BucketType.default: 0>)
@client.command()
@commands.cooldown(1, 60, commands.BucketType.user) # Один раз в 60 секунд на пользователя (глобально)
async def cmd(ctx, ...):
...
@client.listen("on_command_error")
async def cooldown_message(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send(f"{ctx.command.qualified_name} можно использовать только {error.cooldown.rate} раз в {error.cooldown.per} секунд. Попробуйте через {error.retry_after} секунд.")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question