Skip to content

Commit

Permalink
docs: fix issues with slash command guide (#1475)
Browse files Browse the repository at this point in the history
* docs: fix issues with slash command guide

* docs: restore and update error handling

* docs: use print_exception instead of logger

* docs: missed a spot
  • Loading branch information
AstreaTSS authored Jul 7, 2023
1 parent d25d077 commit b4d337b
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions docs/src/Guides/03 Creating Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ This will show up in discord as `/base group command`. There are more ways to ad

=== ":three: Class Definition"
```python
from interactions import SlashCommand

base = SlashCommand(name="base", description="My command base")
group = base.group(name="group", description="My command group")

Expand Down Expand Up @@ -125,7 +127,7 @@ Now that you know all the options you have for options, you can opt into adding

You do that by using the `@slash_option()` decorator and passing the option name as a function parameter:
```python
from interactions import OptionType
from interactions import OptionType, slash_option

@slash_command(name="my_command", ...)
@slash_option(
Expand Down Expand Up @@ -495,25 +497,22 @@ The same principle can be used to reuse autocomplete options.

## Simplified Error Handling

If you want error handling for all commands, you can override `Client` and define your own.
Any error from interactions will trigger `on_command_error`. That includes context menus.
If you want error handling for all commands, you can override the default error listener and define your own.
Any error from interactions will trigger `CommandError`. That includes context menus.

In this example, we are logging the error and responding to the interaction if not done so yet:
```python
from interactions import Client
import traceback
from interactions.api.events import CommandError

class CustomClient(Client):
@listen(disable_default_listeners=True) # tell the dispatcher that this replaces the default listener
async def on_command_error(self, event: CommandError):
logger.error(event.error)
if not event.ctx.responded:
await event.ctx.send("Something went wrong.")

client = CustomErrorClient(...)
@listen(CommandError, disable_default_listeners=True) # tell the dispatcher that this replaces the default listener
async def on_command_error(self, event: CommandError):
traceback.print_exception(event.error)
if not event.ctx.responded:
await event.ctx.send("Something went wrong.")
```

There also is `on_command` which you can overwrite too. That fires on every interactions usage.
There also is `CommandCompletion` which you can overwrite too. That fires on every interactions usage.

## I Need A Custom Parameter Type

Expand Down

0 comments on commit b4d337b

Please sign in to comment.