nocli-handler.js
  • ๐Ÿ”—Links
    • Link to NPM Package
    • Link to Github Package
  • ๐Ÿš€Introduction
    • Welcome
    • Changelog
  • ๐ŸงชGetting Started
    • Setting Up Your Project
  • โ“Guides
    • Instance
      • Providing a MongoDB Connection
      • Things you really need to know
    • Commands
      • Creating a simple "Ping Pong" Command
      • Command Arguments
      • Enabling Slash Commands
      • Deleting a Command
      • Guild and Owner-only Commands
      • Command Aliases
      • Deferring a command reply
      • Running Events inside a Command
      • Command Cooldowns
      • Setting up Autocomplete
      • Required Permissions
  • ๐ŸซClasses
    • NoCliHandler
      • .connectToMongoDB()
    • ChannelCommands
      • .action()
      • .add()
      • .remove()
      • .getAvailableChannels()
    • Command
    • CommandHandler
      • .getValidations()
      • .readFiles()
      • .runCommand()
      • .isCommand()
    • CustomCommands
      • .loadCommands()
      • .create()
      • .delete()
      • .run()
    • DisabledCommands
      • .loadDisabledCommands()
      • .disable()
      • .enable()
      • .isDisabled()
    • PrefixHandler
      • .loadPrefixes()
      • .get()
      • .set()
    • SlashCommands
      • .getCommands()
      • .findCommand()
      • .optionsAreDifferent()
      • .create()
      • .delete()
      • .createOptions()
    • EventHandler
      • .readFiles()
      • .registerEvents()
      • .isEvent()
  • ๐Ÿ› ๏ธUtilities
    • Cooldowns
      • .loadCooldowns()
      • .getKeyFromCooldownUsage()
      • .cancelCooldown()
      • .updateCooldown()
      • .verifyCooldown()
      • .getKey()
      • .canBypass()
      • .start()
      • .canRunAction()
    • handleCommandAutocomplete
    • handleError
    • log
    • getAllFiles
    • importFile
  • ๐Ÿ†ŽDefinitions
    • NoCliCategoryConfiguration
    • NoCliCategoryType
    • ICommand
    • CommandOptions
    • CommandCallbackOptions
    • NoCliCommandCooldown
    • NoCliCommandType
    • cooldownTypesArray
    • NoCliCooldownType
    • NoCliCooldownKeyOptions
    • IEvent
    • EventConfigurationOptions
    • DynamicValidationConfigurationOptions
    • DynamicValidationCheck
    • DynamicValidationCheckFunction
    • NoCliHandlerOptions
    • NoCliCooldownOptions
    • NoCliCooldownConfigOptions
    • MongoDBConnection
    • MongoDBResult
    • DebugOptions
    • ConfigOptions
    • ValidationPluginsOption
    • NoCliEmojiConfigOptions
    • NoCliLanguageType
    • NoCliRuntimeValidationType
    • NoCliSyntaxValidationType
Powered by GitBook
On this page
  • Using autocomplete function
  • End Result:
  1. Guides
  2. Commands

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

device.js
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;
device.ts
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;

End Result:

PreviousCommand CooldownsNextRequired Permissions

Last updated 2 years ago

โ“