Skip to content

Commit b4d337b

Browse files
authored
docs: fix issues with slash command guide (#1475)
* docs: fix issues with slash command guide * docs: restore and update error handling * docs: use print_exception instead of logger * docs: missed a spot
1 parent d25d077 commit b4d337b

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

docs/src/Guides/03 Creating Commands.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ This will show up in discord as `/base group command`. There are more ways to ad
9191

9292
=== ":three: Class Definition"
9393
```python
94+
from interactions import SlashCommand
95+
9496
base = SlashCommand(name="base", description="My command base")
9597
group = base.group(name="group", description="My command group")
9698

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

126128
You do that by using the `@slash_option()` decorator and passing the option name as a function parameter:
127129
```python
128-
from interactions import OptionType
130+
from interactions import OptionType, slash_option
129131

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

496498
## Simplified Error Handling
497499

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

501503
In this example, we are logging the error and responding to the interaction if not done so yet:
502504
```python
503-
from interactions import Client
505+
import traceback
504506
from interactions.api.events import CommandError
505507

506-
class CustomClient(Client):
507-
@listen(disable_default_listeners=True) # tell the dispatcher that this replaces the default listener
508-
async def on_command_error(self, event: CommandError):
509-
logger.error(event.error)
510-
if not event.ctx.responded:
511-
await event.ctx.send("Something went wrong.")
512-
513-
client = CustomErrorClient(...)
508+
@listen(CommandError, disable_default_listeners=True) # tell the dispatcher that this replaces the default listener
509+
async def on_command_error(self, event: CommandError):
510+
traceback.print_exception(event.error)
511+
if not event.ctx.responded:
512+
await event.ctx.send("Something went wrong.")
514513
```
515514

516-
There also is `on_command` which you can overwrite too. That fires on every interactions usage.
515+
There also is `CommandCompletion` which you can overwrite too. That fires on every interactions usage.
517516

518517
## I Need A Custom Parameter Type
519518

0 commit comments

Comments
 (0)