# ModalHandler

`class` in `http` · v0.1.0-next.0

<https://docs.seedcord.org/packages/http/0.1.0-next.0/classes/modal-handler>

Base class for a modal submit handler on the HTTP transport.

Register the customId definitions this handler decodes with `@ModalRoute` and list the same ones in the generic. Read the submitted inputs off `this.event.data.components`. Reply through the handler members. Discord forbids opening a modal in response to a modal, so `showModal` fails compilation on this kind.

```ts
abstract class ModalHandler<
    Defs extends readonly AnyCustomId[]
> extends ComponentHandler<APIModalSubmitInteraction, Defs>
```

## Constructors

### constructor

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

Constructs a new instance of the `InteractionHandler` class

## Properties

### params

```ts
protected params: SingleParams<Defs>
```

The decoded params of the single route this handler is registered for.

Reading this decodes `this.event.data.custom_id` once (cached after the first read) and throws `StaleCustomId` or `InvalidCustomId` when the wire no longer matches the current shape, which the dispatcher boundary turns into a reply. On a handler registered for several routes this is `never`, so use [`match`](/packages/http/0.1.0-next.0/classes/autocomplete-handler#match) instead.

## Methods

### buildSender

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

### deferUpdate

```ts
protected async deferUpdate(): Promise<void>
```

Silently acknowledge, leaving the source message untouched.

### match

```ts
protected async match<Ret>(arms: MatchArms<Defs, Ret>): Promise<Ret>
```

Run the arm for whichever route the component was minted from. Use this only when the handler is registered for several routes. A single-route handler reads `this.params` directly. On a multi-route handler `this.params` is `never`, so match is the only way to read the decoded params.

Provide one arm per registered route, keyed by its prefix, and each arm receives that route's own decoded params. The arms cover every registered route prefix, checked at compile time, and a prefix unmatched at runtime throws `CustomIdMatchArmMissing`. Decoding runs before any arm, so a stale or corrupt wire throws before an arm body executes.

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

### update

```ts
protected async update(
    response: ReplyResponse | string
): Promise<SentMessage>
```

Rewrite the message this modal was opened from (only when a component opened it).
