You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/components.rst
+21-7Lines changed: 21 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -9,15 +9,17 @@ First lets cover the basics. Discord messages can have *components*, such as but
9
9
Sending some components
10
10
_______________________
11
11
12
+
.. note:: This will work in both slash commands, and discord.py commands
13
+
12
14
First we need to create some buttons, lets put them in a list for now. We'll use :meth:`create_button() <discord_slash.utils.manage_components>` to create a green button
13
15
14
16
.. code-block:: python
15
17
16
-
from discord_slash.utils importmanage_components
18
+
from discord_slash.utils.manage_componentsimportcreate_button, create_actionrow
17
19
from discord_slash.model import ButtonStyle
18
20
19
21
buttons = [
20
-
manage_components.create_button(
22
+
create_button(
21
23
style=ButtonStyle.green,
22
24
label="A Green Button"
23
25
),
@@ -27,8 +29,7 @@ So we have a button, but where do we use it. Let's create an action row with :fu
.. note:: This will work in both slash commands, and discord.py commands
41
+
42
+
And to bring it all together, you could use this:
43
+
44
+
.. code-block:: python
45
+
46
+
from discord_slash.utils.manage_components import create_button, create_actionrow
47
+
from discord_slash.model import ButtonStyle
48
+
49
+
await ctx.send("My Message", components=[
50
+
create_actionrow(
51
+
create_button(style=ButtonStyle.green, label="A Green Button"))
52
+
])
41
53
42
54
Now if you've followed along, you have a green button in discord! But theres a problem, whenever you click it you see that the ``interaction failed``. Why is that?
43
55
Well, in Discord, clicking buttons and using slash commands are called ``interactions``, and Discord doesn't know if we've received them or not unless we tell Discord. So how do we do that?
@@ -55,9 +67,11 @@ This method will return a :class:`ComponentContext <discord_slash.context.Compon
55
67
56
68
.. code-block:: python
57
69
70
+
from discord_slash.utils.manage_components import wait_for_component
await button_ctx.edit_origin(content="You pressed a button!")
62
76
63
77
.. note:: It's worth being aware that if you handle the event in the command itself, it will not persist reboots. As such when you restart the bot, the interaction will fail
@@ -77,7 +91,7 @@ Next we'll go over the alternative, a global event handler. This works just the
77
91
Component callbacks
78
92
********************
79
93
80
-
There is one more method - making a function that'll be component callback - triggered when components in specified messages or with specified custom_ids would be activated
94
+
There is one more method - making a function that'll be component callback - triggered when components in a specified message or specific ``custom_id`` are used.
81
95
Let's register our callback function via decorator :meth:`component_callback() <discord_slash.client.SlashCommand.component_callback>`, in similar ways to slash commands.
0 commit comments