forked from Pycord-Development/pycord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcooldown.py
37 lines (28 loc) · 1010 Bytes
/
cooldown.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import discord
from discord.ext import commands
bot = commands.Bot()
# an application command with cooldown
@bot.slash_command()
@commands.cooldown(
1, 5, commands.BucketType.user
) # the command can only be used once in 5 seconds
async def slash(ctx):
await ctx.respond("You can't use this command again in 5 seconds.")
# error handler
@bot.event
async def on_application_command_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.respond("This command is currently on cooldown.")
else:
raise error # raise other errors so they aren't ignored
# a prefixed command with cooldown
@bot.command()
@commands.cooldown(1, 5, commands.BucketType.user)
async def prefixed(ctx):
await ctx.send("You can't use this command again in 5 seconds.")
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send("This command is currently on cooldown.")
else:
raise error