# AutocompleteHandler

`class` in `seedcord` · v0.12.0

<https://docs.seedcord.org/packages/seedcord/0.12.0/classes/autocomplete-handler>

Base class for a Discord autocomplete handler.

Pass the command route(s) from the generated registry as the generic, the same string(s) as `@AutocompleteRoute`. 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,
    Cache extends CacheType = "cached"
>
    extends BaseHandler<AutocompleteInteraction<Cache>>
    implements Handler
```

## Examples

```ts
\@AutocompleteRoute('search')
class SearchAutocomplete extends AutocompleteHandler<'search'> {
    async execute() {
        await this.match({
            query: (value, respond) => respond([{ name: value, value }])
        });
    }
}
```

## Constructors

### constructor

```ts
AutocompleteHandler(
    event: AutocompleteInteraction<Cache>,
    core: Core
)
```

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. Read the focused field from `this.focused`, not here.

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

Provide one arm per autocompletable field across the registered commands. Each arm receives the focused partial value and a `respond` pinned to that field's choice value type. A missing arm is a compile error. A focused field with no arm, only reachable from a stale-deployed command, throws.
