Skip to content

Commit

Permalink
Add documentation page for advanced options example (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluenix2 committed Oct 6, 2021
1 parent 910cbae commit 06f2c4f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ nav:
- Option choices: tutorial/rock-paper-scissors.md
- Multiple options: tutorial/mcdonalds-order.md
- Enum options: tutorial/choices-with-enums.md
- Advanced options: tutorial/advanced-options.md

- Reference:
- Application commands: reference/interactions/commands.md
Expand Down
83 changes: 83 additions & 0 deletions docs/source/tutorial/advanced-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Catifying nicknames

On this page we're gonna go through how to use advanced option types, more
specfically how to take a user object as an option.

## Defining the option

Let's start by taking the usual boilerplate to create a slash command and add
a parameter annotated as `interactions.InteractionUser`:

```python
from wumpy import interactions


app = interactions.InteractionApp(...)


@app.command()
async def catify(
interaction: interactions.CommandInteraction,
target: interactions.InteractionUser,
) -> None:
"""Catify a user's name."""
pass
```

This will tell Wumpy to create an option where the user must specify a user to
send to the command.

By now you should know that there's something missing in this command, let's
add the missin `Option` default.

```python
from wumpy import interactions


app = interactions.InteractionApp(...)


@app.command()
async def catify(
interaction: interactions.CommandInteraction,
target: interactions.InteractionUser = interactions.Option(
description="The user who's name to catify"
),
) -> None:
"""Catify a user's name."""
pass
```

## Finishing the command logic

Like usual with these tutorial let's finish the command to have something fun
to play around with.

All we need to do is append `ᓚᘏᗢ` at the end of the user's name and respond
to the interaction with this.

Usually we respond with a normal response, but let's switch it up this time!

Empheral messages are messages that only the user who invoked the command sees.
In Wumpy they can be used like this:

```python
from wumpy import interactions


app = interactions.InteractionApp(...)


@app.command()
async def catify(
interaction: interactions.CommandInteraction,
target: interactions.InteractionUser = interactions.Option(
description="The user who's name to catify"
),
) -> None:
"""Catify a user's name."""
await interaction.respond(
f"{target.mention}'s new name will be: {target.name + 'ᓚᘏᗢ'}",
empheral=True
)
```

0 comments on commit 06f2c4f

Please sign in to comment.