@client.command(pass_context = True)
async def getalt(ctx):
msg = ["<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ccabadaebea5a9a0bbadbebea9a2fefcfcfc8caba1ada5a0e2afa3a1">[email protected]</a>:Cyber123", "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c4a8a1a5aaa0b6abb6adb2a1b6abb7f5f6f784a3a9a5ada8eaa7aba9">[email protected]</a>:culillo123", "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="03626f6166706a3b436e706d2d606c6e">[email protected]</a>:Albakortoci1", "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0a6e78736e6f643c4a736b62656524696b">[email protected]</a>:toysale22", "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="244a4d474c4845571414151414644349454d480a474b49">[email protected]</a>:nich918273645", "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="24484b404152454a5241414a644349454d480a474b49">[email protected]</a>:Lodelode1", "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f89381949d9e919d949c91969fcac8c9c9b89f95999194d69b9795">[email protected]</a>:emolover123", "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="493b3c2b2b3a3d7a2027092e24282025672a2624">[email protected]</a>:rube541632789mk", "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="761c1705191810040f151d1b1718360f1b171f1a5815191b">[email protected]</a>:fryckman22", "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0a44636961596b736b3b4a62657e676b636624696567">[email protected]</a>:blackout541", "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2b4f4e5d42455a5e4a456b524a43444405484446">[email protected]</a>: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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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
Method 2
I know a method of sending in the channel that cooldown is in process.
@command_name.error
async def command_name_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
em = discord.Embed(title=f"Slow it down bro!",description=f"Try again in {error.retry_after:.2f}s.", color=color_code_here)
await ctx.send(embed=em)
make sure you have imported bucket type. If not –
from discord.ext.commands import cooldown, BucketType
NOTE – Make sure the command cooldown event always has a different name and has to be the_command_name_here.error (don’t make it the_command_name_here , insert the ACTUAL command name there.)
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0