@@ -46,17 +46,21 @@ def in_whitelist_check(
4646 fail_silently : bool = False ,
4747) -> bool :
4848 """
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 .
5050
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.
5258
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.
5661
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.
6064 """
6165 if redirect not in channels :
6266 # It does not make sense for the channel whitelist to not contain the redirection
@@ -92,12 +96,29 @@ def in_whitelist_check(
9296 return False
9397
9498
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 :
97106 """
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 .
99108
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`.
101122 """
102123 # Make it a set so lookup is hash based.
103124 bypass = set (bypass_roles )
@@ -140,10 +161,16 @@ def wrapper(command: Command) -> Command:
140161
141162async def has_any_role_check (ctx : Context , * roles : str | int ) -> bool :
142163 """
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.
144167
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.
147174 """
148175 if not ctx .guild : # Return False in a DM
149176 log .trace (
@@ -166,10 +193,16 @@ async def has_any_role_check(ctx: Context, *roles: str | int) -> bool:
166193
167194async def has_no_roles_check (ctx : Context , * roles : str | int ) -> bool :
168195 """
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.
170203
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 .
173206 """
174207 if not ctx .guild : # Return False in a DM
175208 log .trace (
0 commit comments