# SlashHandler

`class` in `seedcord` · v0.12.0

<https://docs.seedcord.org/packages/seedcord/0.12.0/classes/slash-handler>

Base class for a chat-input (slash) command handler.

Pass the route from the generated registry as the generic, the same string as `@SlashRoute`, then read `this.options` for a single command or `this.match` for several. Command authoring stays plain discord.js, `seedcord codegen` reads its `toJSON()` to type these options.

```ts
abstract class SlashHandler<
    Route extends keyof SlashOptionRegistry,
    Cache extends CacheType = "cached"
> extends InteractionHandler<ChatInputCommandInteraction<Cache>>
```

## Examples

```ts
\@SlashRoute('ban')
class BanHandler extends SlashHandler<'ban'> {
    \@Catchable()
    async execute() {
        const target = this.options.getUser('target'); // User
        const reason = this.options.getString('reason'); // string | null
    }
}
```

## Properties

### options

```ts
protected options: SlashOptions<Route, Cache>
```

The typed options for this command's route. Required options drop the null, choices narrow to their literal union, and only the getters for kinds this command actually uses appear. Use `this.event.options` directly for anything outside this view, such as narrowing a channel option by type.

## Methods

### match

```ts
protected async match<Ret>(
    arms: SlashMatchArms<Route, Cache, Ret>
): Promise<Ret>
```

Run the arm for whichever command fired, when this handler is registered for several routes.

Provide one arm per route, keyed by its route string, and each arm receives that route's typed options. A missing arm is a compile error.
