Skip to content

Commit

Permalink
docs: add docstrings for some properties of InvokableSlashCommand a…
Browse files Browse the repository at this point in the history
…nd `SubCommand` and document `Option`'s attributes (#1112)
  • Loading branch information
Snipy7374 authored Nov 22, 2023
1 parent fb73dbb commit cc5db41
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/1112.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Document the :class:`.Option` attributes, the ``description`` and ``options`` properties for :class:`.ext.commands.InvokableSlashCommand` and the ``description`` and ``body`` properties for :class:`.ext.commands.SubCommand`.
34 changes: 34 additions & 0 deletions disnake/app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,40 @@ class Option:
.. versionadded:: 2.6
max_length: :class:`int`
The maximum length for this option if this is a string option.
.. versionadded:: 2.6
Attributes
----------
name: :class:`str`
The option's name.
description: :class:`str`
The option's description.
type: :class:`OptionType`
The option type, e.g. :class:`OptionType.user`.
required: :class:`bool`
Whether this option is required.
choices: List[:class:`OptionChoice`]
The list of option choices.
options: List[:class:`Option`]
The list of sub options. Normally you don't have to specify it directly,
instead consider using ``@main_cmd.sub_command`` or ``@main_cmd.sub_command_group`` decorators.
channel_types: List[:class:`ChannelType`]
The list of channel types that your option supports, if the type is :class:`OptionType.channel`.
By default, it supports all channel types.
autocomplete: :class:`bool`
Whether this option can be autocompleted.
min_value: Union[:class:`int`, :class:`float`]
The minimum value permitted.
max_value: Union[:class:`int`, :class:`float`]
The maximum value permitted.
min_length: :class:`int`
The minimum length for this option if this is a string option.
.. versionadded:: 2.6
max_length: :class:`int`
The maximum length for this option if this is a string option.
Expand Down
4 changes: 4 additions & 0 deletions disnake/ext/commands/slash_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,12 @@ def parents(

@property
def description(self) -> str:
""":class:`str`: The slash sub command's description. Shorthand for :attr:`self.body.description <.Option.description>`."""
return self.body.description

@property
def body(self) -> Option:
""":class:`.Option`: The API representation for this slash sub command. Shorthand for :attr:`.SubCommand.option`"""
return self.option

async def _call_autocompleter(
Expand Down Expand Up @@ -508,10 +510,12 @@ def _ensure_assignment_on_copy(self, other: SlashCommandT) -> SlashCommandT:

@property
def description(self) -> str:
""":class:`str`: The slash command's description. Shorthand for :attr:`self.body.description <.SlashCommand.description>`."""
return self.body.description

@property
def options(self) -> List[Option]:
"""List[:class:`.Option`]: The list of options the slash command has. Shorthand for :attr:`self.body.options <.SlashCommand.options>`."""
return self.body.options

def sub_command(
Expand Down
2 changes: 1 addition & 1 deletion docs/api/app_commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Option

.. attributetable:: Option

.. autoclass:: Option()
.. autoclass:: Option
:members:

OptionChoice
Expand Down

0 comments on commit cc5db41

Please sign in to comment.