-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start the first documentation page about message components (#1)
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Rick-rolls | ||
|
||
Now that we've fully explored the possibilities with application commands | ||
there's a second part of the interactions API to take a look at! | ||
|
||
Discord calls these message components. | ||
|
||
## Creating buttons | ||
|
||
In Wumpy it is very simple to create one-off buttons, all you need to do is | ||
instance the `Button` class. | ||
|
||
Start with a bare slash command: | ||
|
||
```python | ||
from wumpy import interactions | ||
|
||
|
||
app = interactions.InteractionApp(...) | ||
|
||
|
||
@app.command() | ||
async def link(interaction: interactions.CommandInteraction) -> None: | ||
"""Respond with an unknown link.""" | ||
pass | ||
``` | ||
|
||
Now it is time to create the button. For link buttons there's not as many | ||
fields necessary, only `url` and `label` itself. Like this: | ||
|
||
```python | ||
Button(label='Click me!', url='https://youtu.be/dQw4w9WgXcQ') | ||
``` | ||
|
||
This instance needs to be given to `interaction.respond` inside of two lists. | ||
|
||
Wumpy automatically converts it into the types that Discord expects, which is a | ||
list of ActionRows. Action rows are special components that contain other | ||
components. | ||
|
||
Your code should look like this: | ||
|
||
```python | ||
from wumpy import interactions | ||
|
||
|
||
app = interactions.InteractionApp(...) | ||
|
||
|
||
@app.command() | ||
async def link(interaction: interactions.CommandInteraction) -> None: | ||
"""Respond with an unknown link.""" | ||
await interaction.respond( | ||
components=[[ | ||
Button(label='Click me!', url='https://youtu.be/dQw4w9WgXcQ') | ||
]] | ||
) | ||
``` |