@@ -46,17 +46,21 @@ def in_whitelist_check(
46
46
fail_silently : bool = False ,
47
47
) -> bool :
48
48
"""
49
- Check if a command was issued in a whitelisted context .
49
+ Check if a command was issued in a context that is whitelisted by channel, category, or roles .
50
50
51
- The whitelists that can be provided are:
51
+ Args:
52
+ ctx (:obj:`discord.ext.commands.Context`): The context in which the command is being invoked.
53
+ redirect (int | None): The channel ID to redirect the user to, if any.
54
+ channels (Container[int]): Whitelisted channel IDs. Defaults to ().
55
+ categories (Container[int]): Whitelisted category IDs. Defaults to ().
56
+ roles (Container[int]): Whitelisted role IDs. Defaults to ().
57
+ fail_silently (bool): Whether to fail silently without raising an exception. Defaults to False.
52
58
53
- - `channels`: a container with channel ids for whitelisted channels
54
- - `categories`: a container with category ids for whitelisted categories
55
- - `roles`: a container with with role ids for whitelisted roles
59
+ Returns:
60
+ bool: True if the command is used in a whitelisted context; False otherwise.
56
61
57
- If the command was invoked in a context that was not whitelisted, the member is either
58
- redirected to the `redirect` channel that was passed (default: #bot-commands) or simply
59
- told that they're not allowed to use this particular command (if `None` was passed).
62
+ Raises:
63
+ InWhitelistCheckFailure: If the context is not whitelisted and `fail_silently` is False.
60
64
"""
61
65
if redirect not in channels :
62
66
# It does not make sense for the channel whitelist to not contain the redirection
@@ -92,12 +96,29 @@ def in_whitelist_check(
92
96
return False
93
97
94
98
95
- def cooldown_with_role_bypass (rate : int , per : float , type : BucketType = BucketType .default , * ,
96
- bypass_roles : Iterable [int ]) -> Callable :
99
+ def cooldown_with_role_bypass (
100
+ rate : int ,
101
+ per : float ,
102
+ type : BucketType = BucketType .default ,
103
+ * ,
104
+ bypass_roles : Iterable [int ]
105
+ ) -> Callable :
97
106
"""
98
- Applies a cooldown to a command, but allows members with certain roles to be ignored .
107
+ Decorate a command to have a cooldown, which can be bypassed by users with specified roles .
99
108
100
- NOTE: this replaces the `Command.before_invoke` callback, which *might* introduce problems in the future.
109
+ Note: This replaces the `Command.before_invoke` callback, which *might* introduce problems in the future.
110
+
111
+ Args:
112
+ rate (int): Number of times a command can be used before triggering a cooldown.
113
+ per (float): The duration (in seconds) for how long the cooldown lasts.
114
+ type (:obj:`discord.ext.commands.BucketType`): The type of cooldown (per user, per channel, per guild, etc.).
115
+ bypass_roles (Iterable[int]): An iterable of role IDs that bypass the cooldown.
116
+
117
+ Returns:
118
+ Callable: A decorator that adds the described cooldown behavior to the command.
119
+
120
+ Raises:
121
+ TypeError: If the decorator is not applied to an instance of `Command`.
101
122
"""
102
123
# Make it a set so lookup is hash based.
103
124
bypass = set (bypass_roles )
@@ -140,10 +161,16 @@ def wrapper(command: Command) -> Command:
140
161
141
162
async def has_any_role_check (ctx : Context , * roles : str | int ) -> bool :
142
163
"""
143
- Returns True if the context's author has any of the specified roles.
164
+ Verify if the context's author has any of the specified roles.
165
+
166
+ This check will always fail if the context is a DM, since DMs don't have roles.
144
167
145
- `roles` are the names or IDs of the roles for which to check.
146
- False is always returns if the context is outside a guild.
168
+ Args:
169
+ ctx (:obj:`discord.ext.commands.Context`): The context where the command is being invoked.
170
+ roles (Union[str, int], ...): A collection of role IDs.
171
+
172
+ Returns:
173
+ bool: True if the context's author has at least one of the specified roles; False otherwise.
147
174
"""
148
175
if not ctx .guild : # Return False in a DM
149
176
log .trace (
@@ -166,10 +193,16 @@ async def has_any_role_check(ctx: Context, *roles: str | int) -> bool:
166
193
167
194
async def has_no_roles_check (ctx : Context , * roles : str | int ) -> bool :
168
195
"""
169
- Returns True if the context's author doesn't have any of the specified roles.
196
+ Verify if the context's author doesn't have any of the specified roles.
197
+
198
+ This check will always fail if the context is a DM, since DMs don't have roles.
199
+
200
+ Args:
201
+ ctx (:obj:`discord.ext.commands.Context`): The context where the command is being invoked.
202
+ roles (Union[str, int], ...): A collection of role IDs.
170
203
171
- `roles` are the names or IDs of the roles for which to check.
172
- False is always returns if the context is outside a guild .
204
+ Returns:
205
+ bool: True if the context's author doesn't have any of the specified roles; False otherwise .
173
206
"""
174
207
if not ctx .guild : # Return False in a DM
175
208
log .trace (
0 commit comments