Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

@client.command(pass_context = True)
async def getalt(ctx):
    msg = ["gabrielwarren2000@gmail.com:Cyber123", "leandroriveros123@gmail.com:culillo123", "albesi8@msn.com:Albakortoci1", "dryden6@yahoo.ca:toysale22", "nichlas00100@gmail.com:nich918273645", "lodevanveen@gmail.com:Lodelode1", "kylefielding2011@gmail.com:emolover123", "rubbst3in@gmail.com:rube541632789mk", "jasonfryckman@ymail.com:fryckman22", "NickSaya1@hotmail.com:blackout541", "devinquan@yahoo.com:ploopy101"]
    await client.send_message(ctx.message.author, random.choice(msg))
    await client.send_message(ctx.message.channel, "Alt Has Been Seen To Your DMs")
    await client.purge_from(ctx.message.channel, limit=2)
    await client.send_message(ctx.message.author, "Please Wait 30 Seconds Before Using This Command Again.")

I want to set a 30 sec cooldown for this command.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
624 views
Welcome To Ask or Share your Answers For Others

1 Answer

You should decorate your command with

@commands.cooldown(1, 30, commands.BucketType.user)

This will add a ratelimit of 1 use per 30 seconds per user. docs, example

You can change the BucketType to default, channel or server to create a global, channel or server ratelimit instead, but you can only have 1 cooldown on a command.

Note: In discord.py rewrite (v1.0+) instead of BucketType.server, you have to use BucketType.guild.

This will also cause a CommandOnCooldown exception in on_command_error


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...