# SlashHandler

`class` in `seedcord` · v0.13.0

<https://docs.seedcord.org/packages/seedcord/0.13.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'> {
    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)
```

Constructs a new instance of the `InteractionHandler` class

## Properties

### core

```ts
readonly core: Core
```

### event

```ts
protected readonly event: ValidEvent
```

### logger

```ts
protected readonly logger: Logger
```

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

### execute

```ts
abstract async execute(): Promise<void>
```

Holds the main logic of your handler. The dispatcher calls it after the handler's gates pass, so a gate that refuses stops `execute()` from running.

### 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. A single-route handler reads `this.options` directly instead, match buys nothing there.

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.
