# AutocompleteHandler

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

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

Base class for an autocomplete handler on the HTTP transport.

Pass the command route(s) from the generated registry as the generic. Branch on the focused field with `this.match`, read already-entered sibling options with `this.options`, and find which command fired with `this.route`.

```ts
abstract class AutocompleteHandler<
    Route extends keyof SlashOptionRegistry
> extends BaseHandler<APIApplicationCommandAutocompleteInteraction, Core>
```

## Constructors

### constructor

```ts
AutocompleteHandler(
    event: APIApplicationCommandAutocompleteInteraction,
    core: Core,
    dispatch?: DispatchContext
)
```

Constructs a new instance of the `AutocompleteHandler` class

## Properties

### focused

```ts
protected focused: FocusedField<Route>
```

The focused option for this interaction. `value` is always the raw partial string the user is typing, even for an integer or number option, so coerce it yourself when you need a number.

### options

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

The already-entered options on this command, restricted to the kinds Discord resolves during autocomplete (string, integer, number, boolean) with every read nullable, since a sibling is partial while the user types the focused field. The focused field is on `this.focused`.

### route

```ts
protected route: Route
```

The firing command route, for a field whose completion differs per registered command.

## Methods

### match

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

Run the arm for the focused field. An autocomplete always dispatches by which field is focused, so match is how you read it.

Provide one arm per autocompletable field across the registered commands, keyed by field name. Each arm receives the focused partial value and a `respond` typed to that field's choice value. The arms must cover every autocompletable field, a missing field or an unknown key is a compile error. A focused field with no arm, only reachable from a stale-deployed command, throws at runtime.

### respond

```ts
protected async respond(
    choices: readonly APIApplicationCommandOptionChoice[]
): Promise<void>
```

Send autocomplete suggestions, callback type 8. Prefer [`match`](/packages/http/0.1.0-next.0/classes/autocomplete-handler#match), which restricts each field's choices to its declared type.
