# SlashHandler

`class` in `http` · v0.3.1

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

Base class for a chat-input (slash) command handler on the HTTP transport.

Pass the route from the generated registry as the generic, 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
> extends InteractionHandler<APIChatInputApplicationCommandInteraction>
```

## Constructors

### constructor

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

Constructs a new instance of the `InteractionHandler` class

## Properties

### api

```ts
protected api: API
```

Typed Discord REST API (`@discordjs/core/http-only`) over `core.rest`, one instance per core. The interaction callbacks on `api.interactions` bypass the reply surface. The `no-raw-interaction-acks` rule flags them in handler classes.

### core

```ts
readonly core: TCore
```

### dispatch

```ts
protected readonly dispatch: DispatchContext | undefined
```

### event

```ts
protected readonly event: Event
```

### logger

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

### options

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

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. Rich kinds resolve from the interaction's `resolved` data.

### routeId

```ts
protected readonly routeId: string
```

### sender

```ts
protected readonly sender: TSender
```

## Methods

### buildSender

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

### defer

```ts
protected async defer(opts?: DeferOpts): Promise<void>
```

Show a "thinking" placeholder, then fill it later with [`edit`](/packages/http/0.3.1/classes/slash-handler#edit).

### delete

```ts
protected async delete(target?: TMessage): Promise<void>
```

Delete the initial reply or deferred placeholder. Pass a target to delete a message a prior send returned.

### edit

```ts
protected async edit(
    response: ReplyResponse<TNative> | string
): Promise<TMessage>
```

```ts
protected async edit(
    target: TMessage,
    response: ReplyResponse<TNative> | string
): Promise<TMessage>
```

Rewrite the initial reply or deferred placeholder. The targeted form rewrites a message a prior send returned.

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

### followUp

```ts
protected async followUp(
    response: ReplyResponse<TNative> | string,
    opts?: SendOpts
): Promise<TMessage>
```

Send a new message once the interaction is acknowledged.

### match

```ts
protected async match<Ret>(
    arms: SlashMatchArms<Route, 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.

### reply

```ts
protected async reply(
    response: ReplyResponse<TNative> | string,
    opts?: SendOpts
): Promise<TMessage>
```

Send the initial response, exactly once.

### send

```ts
protected async send(
    response: ReplyResponse<TNative> | string,
    opts?: SendOpts
): Promise<TMessage>
```

Routes to reply, followUp, or edit based on the current ack state.

### showModal

```ts
protected async showModal(
    this: InteractionHandler<
        Exclude<Repliables, APIModalSubmitInteraction>
    >,
    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).
