File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 7
7
intents .message_content = True
8
8
9
9
bot = commands .Bot (command_prefix = commands .when_mentioned_or ("!" ), debug_guilds = [...], intents = intents )
10
-
10
+ bypassing_users = [] # used in the dynamic cooldown below
11
11
12
12
# An application command with cooldown
13
13
@bot .slash_command ()
@@ -32,6 +32,22 @@ async def prefixed(ctx: commands.Context):
32
32
await ctx .send ("You can use this command again in 5 seconds." )
33
33
34
34
35
+ # Dynamic cooldown function; allows for custom cooldown logic such as different cooldowns per-user
36
+ def my_cooldown (message ):
37
+ if message .author .id in bypassing_users :
38
+ return None # Let specific users bypass the cooldown entirely
39
+ elif message .author .get_role (929080208148017242 ):
40
+ return commands .Cooldown (2 , 5 ) # Users with the above role ID can use the command twice in 5 seconds
41
+ else :
42
+ return commands .Cooldown (1 , 10 ) # All other users can use the command once in 10 seconds
43
+
44
+ # A prefixed command with the dynamic cooldown defined above
45
+ @bot .command ()
46
+ @commands .dynamic_cooldown (my_cooldown , commands .BucketType .user )
47
+ async def dynamic (ctx : commands .Context ):
48
+ await ctx .send ("You can use this command again soon." )
49
+
50
+
35
51
# Prefixed command error handler
36
52
@bot .event
37
53
async def on_command_error (ctx : commands .Context , error : commands .CommandError ):
You can’t perform that action at this time.
0 commit comments