# Autocomplete

{% embed url="<https://youtu.be/_67r4wq23BA?t=466>" %}

WOKCommands comes with built in autocomplete handling for slash commands. As of now you must provide custom slash command options and not use inferred arguments.

{% tabs %}
{% tab title="JavaScript" %}
{% code title="os.js" %}

```javascript
const { ApplicationCommandOptionType } = require("discord.js");
const { CommandType } = require("wokcommands");

module.exports = {
  description: "Sets your operating system",
  type: CommandType.SLASH,

  options: [
    {
      name: "operating-system",
      description: "The operating system you use",
      type: ApplicationCommandOptionType.String,
      required: true,
      // Required for autocomplete to work
      autocomplete: true,
    },
  ],

  autocomplete: (command, argument, interaction) => {
    // Easier to view the autocomplete functionality with
    // two versions of Windows
    return ["Windows 10", "Windows 11", "Mac", "Linux"];
  },

  callback: ({ text }) => {
    return {
      content: `Your operating system is ${text}`,
      ephemeral: true,
    };
  },
};
```

{% endcode %}
{% endtab %}

{% tab title="TypeScript" %}
{% code title="os.ts" %}

```typescript
import {
  ApplicationCommandOptionType,
  AutocompleteInteraction,
} from "discord.js";
import { CommandObject, CommandType, CommandUsage } from "wokcommands";
import Command from "wokcommands/src/command-handler/Command";

export default {
  description: "Sets your operating system",
  type: CommandType.SLASH,

  options: [
    {
      name: "operating-system",
      description: "The operating system you use",
      type: ApplicationCommandOptionType.String,
      required: true,
      // Required for autocomplete to work
      autocomplete: true,
    },
  ],

  autocomplete: (
    command: Command,
    argument: string,
    interaction: AutocompleteInteraction
  ) => {
    // Easier to view the autocomplete functionality with
    // two versions of Windows
    return ["Windows 10", "Windows 11", "Mac", "Linux"];
  },

  callback: (options: CommandUsage) => {
    const { text } = options;

    return {
      content: `Your operating system is ${text}`,
      ephemeral: true,
    };
  },
} as CommandObject;
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wornoffkeys.com/commands/autocomplete.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
