docstrings, *args, and error changes

This commit is contained in:
Gnome 2021-09-02 21:24:37 +01:00
parent 7bf90f9e27
commit 8a779ef595
5 changed files with 27 additions and 8 deletions

View File

@ -615,6 +615,8 @@ class Client:
To perform asynchronous setup after the bot is logged in but before To perform asynchronous setup after the bot is logged in but before
it has connected to the Websocket, overwrite this coroutine. it has connected to the Websocket, overwrite this coroutine.
.. versionadded:: 2.0
""" """
pass pass
@ -706,7 +708,7 @@ class Client:
""":class:`.Status`: """:class:`.Status`:
The status being used upon logging on to Discord. The status being used upon logging on to Discord.
.. versionadded: 2.0 .. versionadded:: 2.0
""" """
if self._connection._status in set(state.value for state in Status): if self._connection._status in set(state.value for state in Status):
return Status(self._connection._status) return Status(self._connection._status)

View File

@ -1128,6 +1128,24 @@ class BotBase(GroupMixin):
async def process_slash_commands(self, interaction: discord.Interaction): async def process_slash_commands(self, interaction: discord.Interaction):
"""|coro|
This function processes a slash command interaction into a usable
message and calls :meth:`.process_commands` based on it. Without this
coroutine slash commands will not be triggered.
By default, this coroutine is called inside the :func:`.on_interaction`
event. If you choose to override the :func:`.on_interaction` event,
then you should invoke this coroutine as well.
.. versionadded:: 2.0
Parameters
-----------
interaction: :class:`discord.Interaction`
The interaction to process slash commands for.
"""
interaction.data = cast(ApplicationCommandInteractionData, interaction.data) interaction.data = cast(ApplicationCommandInteractionData, interaction.data)
command_name, command_options = _unwrap_slash_groups(interaction.data) command_name, command_options = _unwrap_slash_groups(interaction.data)
@ -1164,7 +1182,6 @@ class BotBase(GroupMixin):
raise errors.MissingRequiredArgument(param) raise errors.MissingRequiredArgument(param)
elif ( elif (
option["type"] == 3 option["type"] == 3
and " " in option["value"] # type: ignore
and param.kind != param.KEYWORD_ONLY and param.kind != param.KEYWORD_ONLY
and not isinstance(param.annotation, Greedy) and not isinstance(param.annotation, Greedy)
): ):

View File

@ -586,7 +586,7 @@ class ThreadConverter(IDConverter[discord.Thread]):
2. Lookup by mention. 2. Lookup by mention.
3. Lookup by name. 3. Lookup by name.
.. versionadded: 2.0 .. versionadded:: 2.0
""" """
async def convert(self, ctx: Context, argument: str) -> discord.Thread: async def convert(self, ctx: Context, argument: str) -> discord.Thread:

View File

@ -1187,7 +1187,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
if self.slash_command is False: if self.slash_command is False:
return return
elif nested == 3: elif nested == 3:
raise ValueError(f"{self.qualified_name} is too deeply nested!") raise ApplicationCommandRegistrationError(self, f"{self.qualified_name} is too deeply nested!")
payload = { payload = {
"name": self.name, "name": self.name,
@ -1208,7 +1208,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
option: Dict[str, Any] = { option: Dict[str, Any] = {
"name": name, "name": name,
"description": self.option_descriptions[name], "description": self.option_descriptions[name],
"required": param.default is param.empty and not self._is_typing_optional(annotation), "required": (param.default is param.empty and not self._is_typing_optional(annotation)) or param.kind == param.VAR_POSITIONAL,
} }
annotation = cast(Any, annotation) annotation = cast(Any, annotation)
@ -1616,7 +1616,7 @@ class Group(GroupMixin[CogT], Command[CogT, P, T]):
if self.slash_command is False: if self.slash_command is False:
return return
elif nested == 2: elif nested == 2:
raise ValueError(f"{self.qualified_name} is too deeply nested for slash commands!") raise ApplicationCommandRegistrationError(self, f"{self.qualified_name} is too deeply nested!")
return { # type: ignore return { # type: ignore
"name": self.name, "name": self.name,

View File

@ -930,9 +930,9 @@ class ApplicationCommandRegistrationError(ClientException):
command: :class:`Command` command: :class:`Command`
The command that failed to be converted. The command that failed to be converted.
""" """
def __init__(self, command: Command) -> None: def __init__(self, command: Command, msg: str = None) -> None:
self.command = command self.command = command
super().__init__(f"{command.qualified_name} failed to converted to an application command.") super().__init__(msg or f"{command.qualified_name} failed to converted to an application command.")
class FlagError(BadArgument): class FlagError(BadArgument):
"""The base exception type for all flag parsing related errors. """The base exception type for all flag parsing related errors.