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 77intents .message_content = True
88
99bot = commands .Bot (command_prefix = commands .when_mentioned_or ("!" ), debug_guilds = [...], intents = intents )
10-
10+ allowed_users = []
1111
1212# An application command with cooldown
1313@bot .slash_command ()
@@ -32,6 +32,22 @@ async def prefixed(ctx: commands.Context):
3232 await ctx .send ("You can use this command again in 5 seconds." )
3333
3434
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 allowed_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+
3551# Prefixed command error handler
3652@bot .event
3753async def on_command_error (ctx : commands .Context , error : commands .CommandError ):
You can’t perform that action at this time.
0 commit comments