Skip to content

Commit 5363e3f

Browse files
committed
feat(docs): Documented some stuff
1 parent 2979e9e commit 5363e3f

File tree

8 files changed

+89
-17
lines changed

8 files changed

+89
-17
lines changed

discord/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ def on_click(self, custom_id: Optional[Union[Pattern[AnyStr], AnyStr]] = None) -
11591159
if so, the decorated function is called.
11601160
11611161
The function this is attached to must take the same parameters as a
1162-
`raw_button_click-Event <https://discordpy-message-components.rtfd.io/en/latest/additions.html#on_raw_button_click>`_.
1162+
:func:`on_raw_button_click` event.
11631163
11641164
.. important::
11651165
The function decorated must be a coroutine, if not, :exc:`TypeError` is raised.
@@ -1226,7 +1226,7 @@ def on_select(self, custom_id: Optional[Union[Pattern[AnyStr], AnyStr]] = None)
12261226
A decorator with which you can assign a function to a specific :class:`~discord.SelectMenu` (or its custom_id).
12271227
12281228
The function this is attached to must take the same parameters as a
1229-
`raw_selection_select-Event <https://discordpy-message-components.rtfd.io/en/latest/additions.html#on_raw_selection_select>`_.
1229+
:func:`on_raw_selection_select` event.
12301230
12311231
.. important::
12321232
The decorated function must be a coroutine, if not, :exc:`TypeError` is raised.
@@ -1284,11 +1284,11 @@ def on_submit(self, custom_id: Optional[Union[Pattern[AnyStr], AnyStr]] = None)
12841284
[Awaitable[Any]], Awaitable[Any]
12851285
]:
12861286
"""
1287-
A decorator that registers an on_modal_submit event that checks on execution if the ``custom_id's`` are the same;
1287+
A decorator that registers an :func:`on_modal_submit` event that checks on execution if the ``custom_id's`` are the same;
12881288
if so, the decorated function is called.
12891289
12901290
The function this is attached to must take the same parameters as a
1291-
`raw_button_click-Event <https://discordpy-message-components.rtfd.io/en/latest/addition.html#on_modal_submit>`_.
1291+
:func`on_modal_submit` event.
12921292
12931293
.. important::
12941294
The decorated function must be a coroutine, if not, :exc:`TypeError` is raised.

discord/ext/commands/bot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def add_interaction_listener(self, _type, func, custom_id: re.Pattern):
432432
This adds an interaction(decorator) like :meth:`on_click` or :meth:`on_select` to the client listeners.
433433
434434
.. note::
435-
This should not use manuel; only cogs use this to register them.
435+
This should not use directly; only cogs use this to register them.
436436
437437
"""
438438
try:
@@ -450,7 +450,7 @@ def remove_interaction_listener(self, _type, func, custom_id: re.Pattern):
450450
This removes an interaction(decorator) like :meth:`on_click` or :meth:`on_select` from the client listeners.
451451
452452
.. note::
453-
This should not use manuel; only cogs use this to remove them.
453+
This should not use directly; only cogs use this to remove them.
454454
455455
"""
456456
try:

discord/ext/commands/cog.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def on_click(cls, custom_id: Optional[Union[Pattern[AnyStr], AnyStr]] = None) ->
343343
if so, the :func:`func` is called.
344344
345345
The function this is attached to must take the same parameters as a
346-
`raw_button_click-Event <https://discordpy-message-components.rtfd.io/en/latest/additions.html#on_raw_button_click>`_.
346+
:func:`on_raw_button_click` event.
347347
348348
.. important::
349349
The func must be a coroutine, if not, :exc:`TypeError` is raised.
@@ -399,7 +399,7 @@ def on_select(cls, custom_id: Optional[Union[Pattern[AnyStr], AnyStr]] = None) -
399399
A decorator with which you can assign a function to a specific :class:`SelectMenu` (or its custom_id).
400400
401401
The function this is attached to must take the same parameters as a
402-
`raw_selection_select-Event <https://discordpy-message-components.rtfd.io/en/latest/additions.html#on_raw_selection_select>`_.
402+
:func:`on_raw_selection_select` event.
403403
404404
.. important::
405405
The func must be a coroutine, if not, :exc:`TypeError` is raised.
@@ -456,11 +456,11 @@ def on_submit(self, custom_id: Optional[Union[Pattern[AnyStr], AnyStr]] = None)
456456
[Awaitable[Any]], Awaitable[Any]
457457
]:
458458
"""
459-
A decorator that registers an on_modal_submit event that checks on execution if the ``custom_id's`` are the same;
459+
A decorator that registers an :attr:`on_modal_submit` event that checks on execution if the ``custom_id's`` are the same;
460460
if so, the :func:`func` is called.
461461
462462
The function this is attached to must take the same parameters as a
463-
`raw_button_click-Event <https://discordpy-message-components.rtfd.io/en/latest/additions.html#on_modal_submit>`_.
463+
:func:`on_modal_submit`.
464464
465465
.. important::
466466
The func must be a coroutine, if not, :exc:`TypeError` is raised.

discord/interactions.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ def channel(self) -> Union[DMChannel, TextChannel, ThreadChannel, VoiceChannel]:
755755
"""
756756
The channel where the interaction was invoked in.
757757
758-
:returns: Union[:class:`~discord.TextChannel`, :class:`~discord.ThreadChannel`, :class:`~discord.DMChannel`, :class`~discord.VoiceChannel`]
758+
:returns: Union[:class:`~discord.TextChannel`, :class:`~discord.ThreadChannel`, :class:`~discord.DMChannel`, :class:`~discord.VoiceChannel`]
759759
"""
760760
return getattr(self, '_channel', self.guild.get_channel(self.channel_id)
761761
if self.guild_id else self._state.get_channel(self.channel_id))
@@ -781,7 +781,7 @@ def message_is_hidden(self) -> bool:
781781

782782
@property
783783
def bot(self):
784-
"""Union[:class:`~discord.Client`/:class:`~discord.ext.commands.Bot`]: The :class:`~discord.Client`/:class:`~discord.ext.commands.Bot` instance of the bot."""
784+
"""Union[:class:`~discord.Client`, :class:`~discord.ext.commands.Bot`]: The :class:`~discord.Client`/:class:`~discord.ext.commands.Bot` instance of the bot."""
785785
return self._state._get_client()
786786

787787
@classmethod
@@ -798,6 +798,9 @@ def from_type(cls, state, data):
798798

799799

800800
class ApplicationCommandInteraction(BaseInteraction):
801+
"""
802+
Represents the data of an interaction that will be received when a :class:`discord.SlashCommand`, :class:`discord.UserCommand` or :class:`discord.MessageCommand` is used.
803+
"""
801804
def __init__(self, *args, **kwargs):
802805
super().__init__(*args, **kwargs)
803806
if self.data.type.user:
@@ -834,8 +837,12 @@ async def defer(self, hidden: bool = False) -> Union[Message, EphemeralMessage]:
834837

835838

836839
class ComponentInteraction(BaseInteraction):
840+
"""
841+
Represents the data of an interaction which will be received when a :class:`~discord.SelectMenu` or :class:`~discord.Button` is used.
842+
"""
837843
@property
838844
def component(self) -> Union[Button, SelectMenu]:
845+
"""Union[:class:`~discord.Button`, :class:`~discord.SelectMenu`]: The component that was used"""
839846
if self._component is None:
840847
custom_id = self.data.custom_id
841848
if custom_id:
@@ -864,18 +871,21 @@ async def defer(self,
864871
Weather only the author of the command should see this, default :obj:`True`
865872
866873
.. note::
867-
Only for :class:`~discord.InteractionCallbackType.deferred_msg_with_source` (``5``).
874+
Only for :attr:`~discord.InteractionCallbackType.deferred_msg_with_source` (``5``).
868875
869876
Returns
870877
-------
871878
Optional[Union[:class:`~discord.Message, :class:`~discord.EphemeralMessage`]]:
872-
The message containing the loading-state if `class`~discord.InteractionCallbackType.deferred_msg_with_source` (``5``) is used, else :obj:`None`.
879+
The message containing the loading-state if :class:`~discord.InteractionCallbackType.deferred_msg_with_source` (``5``) is used, else :obj:`None`.
873880
"""
874881
data = await super()._defer(type, hidden)
875882
return data
876883

877884

878885
class AutocompleteInteraction(BaseInteraction):
886+
"""
887+
Represents the data of an interaction that will be received when autocomplete for a :class:`discord.SlashCommandOption` with :attr:`~discord.SlashCommandOption.autocomplete` set to :obj:`True`.
888+
"""
879889
@property
880890
def focused_option(self) -> 'InteractionDataOption':
881891
""":class:`~discord.InteractionDataOption`: Returns the currently focused option."""
@@ -916,7 +926,7 @@ async def send_choices(self, choices: List[SlashCommandOptionChoice]) -> None:
916926

917927
@utils.copy_doc(send_choices)
918928
async def suggest(self, choices: List[SlashCommandOptionChoice]) -> None:
919-
"""An aliase for :meth:`send_choices`"""
929+
"""An aliase for :meth:`.send_choices`"""
920930
return await self.send_choices(choices)
921931

922932
async def respond(self, *args, **kwargs):
@@ -927,6 +937,9 @@ async def defer(self, *args, **kwargs):
927937

928938

929939
class ModalSubmitInteraction(BaseInteraction):
940+
"""
941+
Represents the data of an interaction that will be received when the ``Submit`` button of a :class:`~discord.Modal` is pressed.
942+
"""
930943
def get_field(self, custom_id) -> Union['TextInput', None]:
931944
"""Optional[:class:`~discord.TextInput`]: Returns the field witch :attr:`~discord.TextInput.custom_id` match or :class:`None`"""
932945
for ar in self.data.components:

docs/api.rst

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,64 @@ to handle it, which defaults to print a traceback and ignoring the exception.
944944
:param payload: The payload containing all the information
945945
:type payload: :class:`AutoModActionPayload`
946946

947+
.. function:: on_button_click(interaction, button)
948+
949+
Called when a :class:`Button`, that is attached to a :class:`Message` **wich is in the internal cache**, is pressed.
950+
951+
.. note::
952+
In general it is more efficient to use :func:`~Client.on_click`/:func:`ext.commands.Cog.on_click` instead of this and :func:`on_raw_button_click` to make a callback for buttons
953+
954+
:param interaction: The Interaction-object with all his attributes and methods to respond to the interaction
955+
:type interaction: :class:`~discord.ComponentInteraction`
956+
:param button: The button that was pressed. (this is also available under :attr:`discord.ComponentInteraction.component`).
957+
:type button: :class:`Button`
958+
959+
.. function:: on_raw_button_click(interaction, button)
960+
961+
Called when a :class:`Button`, that is attached to **any** :class:`Message` of the bot, is pressed.
962+
963+
.. warning::
964+
This may be removed and be included in :func:`on_button_click` in a future release
965+
966+
:param interaction: The Interaction-object with all his attributes and methods to respond to the interaction
967+
:type interaction: :class:`~discord.ComponentInteraction`
968+
:param button: The button that was pressed. (this is also available under :attr:`discord.ComponentInteraction.component`).
969+
:type button: :class:`Button`
970+
971+
.. function:: on_selection_select(interaction, select_menu)
972+
973+
Called when a :class:`SelectMenu`, that is attached to a :class:`Message` **wich is in the internal cache**, is used.
974+
975+
.. note::
976+
In general it is more efficient to use :func:`~Client.on_select`/:func:`ext.commands.Cog.on_select` instead of this and :func:`on_raw_selection_select` to make a callback for select menus
977+
978+
:param interaction: The Interaction-object with all his attributes and methods to respond to the interaction
979+
:type interaction: :class:`~discord.ComponentInteraction`
980+
:param select_menu: The :class:`SelectMenu` but with the :attr:`SelectMenu.values` set wich contains a list of the selected :attr:`~SelectMenu.options`. (this is also available under :attr:`discord.ComponentInteraction.component`).
981+
:type select_menu: :class:`SelectMenu`
982+
983+
.. function:: on_raw_selection_select(interaction, select_menu)
984+
985+
Called when a :class:`SelectMenu`, that is attached to **any** :class:`Message` of the bot, is used.
986+
987+
.. warning::
988+
This may be removed and be included in :func:`on_selection_select` in a future release
989+
990+
:param interaction: The Interaction-object with all his attributes and methods to respond to the interaction
991+
:type interaction: :class:`~discord.ComponentInteraction`
992+
:param select_menu: The :class:`SelectMenu` but with the :attr:`SelectMenu.values` set wich contains a list of the selected :attr:`~SelectMenu.options`. (this is also available under :attr:`discord.ComponentInteraction.component`).
993+
:type select_menu: :class:`SelectMenu`
994+
995+
.. function:: on_modal_submit(interaction)
996+
997+
Called when a user press the ``Submit`` button in a :class:`Modal`.
998+
999+
.. note::
1000+
In general it is more efficient to use :func:`~Client.on_submit`/:func:`ext.commands.Cog.on_submit` instead of this to make a callback for modals
1001+
1002+
:param interaction: he Interaction-object with all his attributes and methods to respond to the interaction
1003+
:type interaction: :class:`~discord.ModalSubmitInteraction`
1004+
9471005
.. _discord-api-utils:
9481006

9491007
Utility Functions

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
sys.setrecursionlimit(15000)
2323

24-
2524
sys.path.insert(0, os.path.abspath('..'))
2625
sys.path.append(os.path.abspath('extensions'))
2726

@@ -57,6 +56,7 @@
5756
'sphinx.ext.intersphinx',
5857
'sphinxcontrib.contentui',
5958
'sphinx.ext.napoleon',
59+
'sphinxext.opengraph',
6060
'sphinxcontrib_trio',
6161
'details',
6262
'exception_hierarchy',

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
:target: https://pypi.org
4848

4949
.. centered::
50-
**Visit on** |PyPI| **PyPI** `here <https://pypi.org/project/discord.py-message-components>`_
50+
**Visit on** |PyPI| **PyPI** `here <https://pypi.org/project/discord.py-message-components>`_
5151

5252

5353
discord.py-message-components is a modern, easy to use, feature-rich, and async ready API wrapper

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
sphinxcontrib_trio
22
sphinxcontrib-contentui==0.2.5
3+
sphinxext-opengraph
34
Jinja2 >.0.3
45
Pigments
56
typing-extensions

0 commit comments

Comments
 (0)