Setting up Autocomplete
A search-based command needs an autocomplete for a user to reference the results, and the user can use that result for a command option.
Using autocomplete
function
autocomplete
functionautocomplete
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.
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;
End Result:

Last updated