N
N
NekIT2021-09-10 19:52:46
Python
NekIT, 2021-09-10 19:52:46

Discord bot on discord.py. How to make a delay for the use of commands by one user?

For example, so that the same user can ban once an hour and no more.
I am attaching the command code:

@Bot.command(pass_context=True)
@commands.has_role('admin')
async def ban(ctx, member: discord.Member, days=1):
    if user is None:
        await ctx.send(f'{error_emoji} **Пожалуйста, укажите пользователя!** {error_emoji}')
    else:
        try:
            await client.ban(member, delete_message_days=0)
            await client.say('User banned for **' + str(days) + ' day(s)**')
            ban_list.append(member)
            day_list.append(days * 24 * 60 * 60)
            server_list.append(ctx.message.server)
        except:
            await client.say('Error! User not active')
        await client.say('You do not have permission to ban users!')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Whitly, 2021-09-10
@NekIT_049

You can use @commands.cooldown(rate, per, type)
How to use it on the Discord Py site
But in short
rate (int) is how many times a person can write a command before the delay is activated
per (float) is the delay time (in seconds)
type - there are many types in discord py itself, but commands.BucketType.user will do in your case

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question