# SlashHandler

`class` in `gateway` · v0.1.0-next.3

<https://docs.seedcord.org/packages/gateway/0.1.0-next.3/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'> {
    async execute() {
        const target = this.options.getUser('target'); // User
        const reason = this.options.getString('reason'); // string | null
    }
}
```

## Constructors

### constructor

```ts
InteractionHandler(
    event: Repliable,
    core: Core,
    dispatch?: DispatchContext
)
```

Constructs a new instance of the `InteractionHandler` class

## 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

### buildSender

```ts
protected buildSender(
    event: Event,
    _core: Core,
    routeId: string
): ReplySender
```

### match

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

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

Provide one arm per registered route, keyed by its route string, and each arm receives that route's own narrowed options. The arms must cover every route in the generic, a missing route or an unknown key is a compile error.

### showModal

```ts
protected async showModal(
    this: InteractionHandler<NonModalInteraction>,
    modal: ModalLike
): Promise<void>
```

Open a modal. Must be the initial response to this interaction. The modal kind rejects this call at compile time (Discord forbids a modal in response to a modal).
