> For the complete documentation index, see [llms.txt](https://tribui141108.gitbook.io/nocli-handler.js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tribui141108.gitbook.io/nocli-handler.js/guides/commands/setting-up-autocomplete.md).

# Setting up Autocomplete

### Using `autocomplete` function

`autocomplete` function lets you specify the data to display to the user, while the command handler will take care of the results returned by the function.

Let's create a new sample Slash command called `device`, which asks the user what device they are using, and return a message with what they selected.

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

```javascript
const { NoCliCommandType } = require("nocli-handler.js");

/**
 * @type {import("nocli-handler.js").ICommand}
 */
const Command = {
    description: "Asks what device you are using",
    type: NoCliCommandType.Slash,
    expectedArgs: '<device>',
    minArgs: 1,
    maxArgs: 1,
    autocomplete: (interaction, command, args) => { // <-- Creates a new
        //                                                 Autocomplete instance
        return ["Desktop", "Laptop", "Phone", "Tablet"]
    },
    callback: ({ client, interaction, args, text }) => {
        return `You chose ${args.join(' ')}`;
    }
}

module.exports = Command;
```

{% endcode %}
{% endtab %}

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

```typescript
import { ICommand, NoCliCommandType } from "nocli-handler.js";

export default {
    description: "Asks what device you are using",
    type: NoCliCommandType.Slash,
    expectedArgs: '<device>',
    minArgs: 1,
    maxArgs: 1,
    autocomplete: (interaction, command, args) => { // <-- Creates a new
        //                                                 Autocomplete instance
        return ["Desktop", "Laptop", "Phone", "Tablet"]
    },
    callback: ({ client, interaction, args, text }) => {
        return `You chose ${args.join(' ')}`;
    }
} as ICommand;
```

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

### End Result:

![](/files/njulD0tCgIvLAqzMH03E)

![](/files/92dj4Kc8LKd8PLnl408R)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://tribui141108.gitbook.io/nocli-handler.js/guides/commands/setting-up-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.
