Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 58c2042

Browse files
committed
Update docs
1 parent b754906 commit 58c2042

File tree

8 files changed

+87
-14
lines changed

8 files changed

+87
-14
lines changed

discord/ext/slash/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,30 @@ async def repeat( # command name
4646
Notably, ``ctx.message`` does not exist, because slash commands can be run
4747
completely without the involvement of messages. However, channel and author
4848
information is still available.
49+
* On the other hand, :class:`~discord.ext.slash.ComponentContext` does have a
50+
:attr:`~discord.ext.slash.ComponentContext.message` attribute
51+
available to message component callbacks.
4952
* All descriptions are **required**.
50-
* You must grant the bot ``applications.commands`` permissions in the OAuth2 section of the developer dashboard.
53+
* You must grant the bot ``applications.commands`` permissions in the OAuth2
54+
section of the developer dashboard.
5155
52-
See the `docs <https://discord-ext-slash.rtfd.io>`_.
56+
See the `docs <https://discord-ext-slash.rtfd.io>`_ as well as the
57+
`demo bot <https://github.com/Kenny2github/discord-ext-slash/blob/main/demo_bot.py>`_.
5358
'''
5459
from __future__ import annotations
5560
from .simples import (
5661
SlashWarning, ApplicationCommandOptionType,
5762
ApplicationCommandPermissionType, InteractionType, InteractionResponseType,
58-
InteractionCallbackType, CallbackFlags, ChoiceEnum, ButtonStyle
63+
InteractionCallbackType, CallbackFlags, ChoiceEnum, ButtonStyle,
64+
PartialRole, PartialCategoryChannel, PartialMember, PartialObject,
65+
PartialTextChannel, PartialVoiceChannel
5966
)
6067
from .option import Option, Choice
6168
from .components import (
6269
MessageComponent, ActionRow, Button,
6370
SelectMenu, SelectOption
6471
)
72+
from .message import ComponentedMessage
6573
from .command import (
6674
BaseCallback, Command, Group, cmd, group, permit,
6775
callback, CommandPermissionsDict, ComponentCallback

discord/ext/slash/bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class SlashBot(commands.Bot):
5353
Create a :class:`Group` with the decorated coroutine and ``**kwargs``
5454
and add it to :attr:`slash`.
5555
56-
.. decoratormethod:: component_callback(matcher, ttl, **kwargs)
56+
.. decoratormethod:: component_callback(matcher, ttl=15min, **kwargs)
5757
5858
Create a :class:`ComponentCallback` with the decorated coroutine
5959
and ``**kwargs`` and add it to :attr:`comp_callbacks`.

discord/ext/slash/components.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def to_dict(self) -> dict:
2929
return {'type': self.type}
3030

3131
class ActionRow(MessageComponent):
32-
"""A container for other components.
32+
r"""A container for other components.
3333
3434
This can be instantiated either like
3535
``ActionRow(component1, component2)``
@@ -39,9 +39,9 @@ class ActionRow(MessageComponent):
3939
The first of one or multiple subcomponents, *or*
4040
an iterable of subcomponents.
4141
:type first: Union[Button, SelectMenu, Iterable[Button]]
42-
:param *args:
42+
:param \*args:
4343
The rest of the subcomponents, if ``first`` is the first.
44-
:type *args: Button
44+
:type \*args: Button
4545
4646
.. attribute:: components
4747
:type: list[Union[Button, SelectMenu]]
@@ -171,6 +171,16 @@ def to_dict(self) -> dict:
171171
class SelectMenu(MessageComponent):
172172
"""A select menu for picking from choices.
173173
174+
When using this component, the values selected will be passed to the
175+
callback as variable-count arguments, which must be received like so:
176+
177+
.. code-block:: python
178+
179+
@callback(menu_id)
180+
async def menu_callback(ctx: ComponentContext, *values: str):
181+
# values are now the string values of the options
182+
# specified on the select menu
183+
174184
.. attribute:: custom_id
175185
:type: str
176186

discord/ext/slash/context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,10 @@ class ComponentContext(BaseContext):
540540
Attributes described below are in addition or in place of
541541
those defined in :class:`BaseContext`.
542542
543+
.. attribute:: message
544+
:type: ComponentedMessage
545+
546+
The message that the component is attached to.
543547
.. attribute:: command
544548
:type: Optional[ComponentCallback]
545549

discord/ext/slash/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .components import MessageComponent
44

55
class ComponentedMessage(discord.Message):
6-
"""Monkeypatch discord.py's Message to include components."""
6+
"""Monkeypatch :class:`discord.Message` to include components."""
77

88
__slots__ = discord.Message.__slots__ + ('components',)
99

discord/ext/slash/simples.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,20 @@ class ButtonStyle(IntEnum):
146146
""":class:`Button` appearance styles.
147147
148148
.. attribute:: PRIMARY
149+
150+
Blurple primary-action button.
149151
.. attribute:: SECONDARY
152+
153+
Gray secondary-action button.
150154
.. attribute:: SUCCESS
155+
156+
Green confirmation button.
151157
.. attribute:: DANGER
158+
159+
Red destructive-action button.
152160
.. attribute:: LINK
161+
162+
Gray link button with link icon.
153163
"""
154164
PRIMARY = 1
155165
SECONDARY = 2

docs/discord-ext-slash.rst

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Decorators
99
.. autodecorator:: cmd
1010
.. autodecorator:: group
1111
.. autodecorator:: permit
12+
.. autodecorator:: callback
1213

1314
Classes
1415
-------
@@ -18,29 +19,55 @@ The Bot
1819

1920
.. autoclass:: SlashBot
2021

22+
Base Classes
23+
~~~~~~~~~~~~
24+
25+
.. autoclass:: BaseContext
26+
.. autoclass:: BaseCallback
27+
.. autoclass:: MessageComponent
28+
2129
Interaction Context
2230
~~~~~~~~~~~~~~~~~~~
2331

2432
.. autoclass:: Context
33+
:show-inheritance:
2534
.. autoclass:: Interaction
35+
.. autoclass:: ComponentContext
36+
:show-inheritance:
2637

2738
Slash Commands
2839
~~~~~~~~~~~~~~
2940

3041
.. autoclass:: Command
42+
:show-inheritance:
3143
.. autoclass:: Group
3244

45+
46+
Message Components
47+
~~~~~~~~~~~~~~~~~~
48+
49+
.. autoclass:: ComponentCallback
50+
.. autoclass:: ActionRow
51+
:show-inheritance:
52+
.. autoclass:: Button
53+
:show-inheritance:
54+
.. autoclass:: SelectMenu
55+
:show-inheritance:
56+
.. autoclass:: SelectOption
57+
3358
Data Classes
3459
~~~~~~~~~~~~
3560

3661
.. autoclass:: Option
3762
.. autoclass:: Choice
3863

3964
Miscellaneous
40-
~~~~~~~~~~~~~
65+
-------------
4166

4267
.. autoclass:: SlashWarning
4368
.. autoclass:: CommandPermissionsDict
69+
.. autoclass:: ComponentedMessage
70+
:show-inheritance:
4471

4572
Partial Objects
4673
~~~~~~~~~~~~~~~
@@ -62,14 +89,15 @@ information that discord.py prefers (most notably guild information).
6289
:show-inheritance:
6390

6491
Enums
65-
-----
92+
~~~~~
6693

6794
.. autoclass:: ApplicationCommandOptionType
6895
.. autoclass:: ApplicationCommandPermissionType
6996
.. autoclass:: InteractionCallbackType
97+
.. autoclass:: InteractionResponseType
7098
.. autoclass:: CallbackFlags
71-
.. autoclass:: MessageFlags
7299
.. autoclass:: ChoiceEnum
100+
.. autoclass:: ButtonStyle
73101

74102
Events
75103
------
@@ -83,7 +111,7 @@ Events
83111
Triggered immediately after :meth:`SlashBot.register_commands` to give an
84112
opportunity to register dynamic permissions in code before pushing to the
85113
API. If overriding using @:meth:`discord.Client.event`, you must await
86-
:meth:`-SlashBot.register_permissions` at the end of the event handler.
114+
:meth:`SlashBot.register_permissions` at the end of the event handler.
87115
See ``/stop`` in ``demo_bot.py`` for an example.
88116

89117
.. function:: on_before_slash_command_invoke(ctx: Context)
@@ -93,4 +121,17 @@ Events
93121
.. function:: on_after_slash_command_invoke(ctx: Context)
94122

95123
Triggered immediately after a *successful* slash command invocation.
96-
Failed invocations will trigger :func:`discord.on_command_error` instead.
124+
Failed invocations will trigger :func:`discord.on_command_error` instead.
125+
126+
.. function:: on_before_component_callback_invoke(ctx: ComponentContext)
127+
128+
Triggered immediately before a message component callback is invoked.
129+
130+
.. function:: on_after_component_callback_invoke(ctx: ComponentContext)
131+
132+
Triggered immediately after a successful callback invocation.
133+
134+
.. function:: on_component_callback_deregister(callback: ComponentCallback)
135+
136+
Triggered when a component callback is deregistered, either automatically
137+
as part of TTL expiry / use counting or manually.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
longdesc = match('^([\'"])\\1{2}(.*?)\\1{3}', contents, S).group(2)
1010
version = match(r'[\s\S]*__version__[^\'"]+[\'"]([^\'"]+)[\'"]', contents).group(1)
1111
del contents
12-
longdesc = sub(':class:`~?([^`]+)`', r'``\1``', longdesc)
12+
longdesc = sub(':(?:class|attr):`~?([^`]+)`', r'``\1``', longdesc)
1313

1414
with open(os.path.join(os.path.dirname(__file__),
1515
'README.rst'), 'w') as f2:

0 commit comments

Comments
 (0)