3838
3939
4040class Bucket (enum .Enum ):
41+ """
42+ Enum values for the different cooldown buckets.
43+
44+ Parameters
45+ ------------
46+ default: :class:`enum.Enum`
47+ The default bucket.
48+ channel: :class:`enum.Enum`
49+ Cooldown is shared amongst all chatters per channel.
50+ member: :class:`enum.Enum`
51+ Cooldown operates on a per channel basis per user.
52+ user: :class:`enum.Enum`
53+ Cooldown operates on a user basis across all channels.
54+ subscriber: :class:`enum.Enum`
55+ Cooldown for subscribers.
56+ mod: :class:`enum.Enum`
57+ Cooldown for mods.
58+ """
4159
4260 default = 0
4361 channel = 1
@@ -48,6 +66,41 @@ class Bucket(enum.Enum):
4866
4967
5068class Cooldown :
69+ """
70+ Cooldown decorator values.
71+
72+ Parameters
73+ ------------
74+ rate: :class:`int`
75+ How many times the command can be invoked before triggering a cooldown inside a time frame.
76+ per: :class:`float`
77+ The amount of time in seconds to wait for a cooldown when triggered.
78+ bucket: :class:`Bucket`
79+ The bucket that the cooldown is in.
80+
81+ Examples
82+ ----------
83+
84+ .. code:: py
85+
86+ # Restrict a command to once every 10 seconds on a per channel basis.
87+ @commands.cooldown(rate=1, per=10, bucket=commands.Bucket.channel)
88+ @commands.command()
89+ async def my_command(self, ctx: commands.Context):
90+ pass
91+
92+ # Restrict a command to once every 30 seconds for each individual channel a user is in.
93+ @commands.cooldown(rate=1, per=30, bucket=commands.Bucket.member)
94+ @commands.command()
95+ async def my_command(self, ctx: commands.Context):
96+ pass
97+
98+ # Restrict a command to 5 times every 60 seconds globally for a user.
99+ @commands.cooldown(rate=5, per=60, bucket=commands.Bucket.user)
100+ @commands.command()
101+ async def my_command(self, ctx: commands.Context):
102+ pass
103+ """
51104
52105 __slots__ = ("_rate" , "_per" , "bucket" , "_window" , "_tokens" , "_cache" )
53106
0 commit comments