WOKCommands
  • WOKCommands Documentation
  • Useful Links
    • Setup & Options object
    • 🧠 Build a website dashboard, monetize your bot, and get more users
    • 💰 $100 in FREE Hosting Credits
    • 🙋‍♂️ Support Server
    • 📺 YouTube Channel
  • Commands
    • Ping pong command example
    • Command properties
    • Correct argument usage
    • Command initialization method
    • Bot owner only commands
    • Test servers
    • Cooldowns
    • Required permissions
    • Slash commands
    • Inferred slash command arguments
    • Custom slash command arguments
    • Autocomplete
  • Command Validations
    • Validation setup
    • Runtime validations
    • Syntax validations
  • Event Handler
    • Event Handling
    • Dynamic Validations
  • Features
    • Features
  • Built-in commands and features
    • Enabling and disabling commands
    • Configurable required roles
    • Configurable required permissions
    • Per-guild prefixes
    • Customizable channel specific commands
    • Custom commands
Powered by GitBook
On this page

Was this helpful?

  1. Commands

Autocomplete

PreviousCustom slash command argumentsNextValidation setup

Last updated 1 year ago

Was this helpful?

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.

os.js
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,
    };
  },
};
os.ts
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;