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

Custom slash command arguments

PreviousInferred slash command argumentsNextAutocomplete

Last updated 1 year ago

Was this helpful?

Sometimes you may want to pass in your own objects to your slash command. This gives you more control over the exact details of your arguments.

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

module.exports = {
  description: "Adds numbers together",

  // Create a legacy and slash command
  type: CommandType.BOTH,

  // An array of
  // https://discord.js.org/#/docs/discord.js/main/typedef/ApplicationCommandOption
  options: [
    {
      name: "num1",
      description: "The first number",
      type: ApplicationCommandOptionType.Number,
      required: true,
    },
    {
      name: "num2",
      description: "The second number",
      type: ApplicationCommandOptionType.Number,
      required: true,
    },
  ],

  callback: ({ args }) => {
    const sum = args.reduce((acc, cur) => {
      return acc + Number(cur);
    }, 0);

    return `The sum is ${sum}`;
  },
};
add.ts
import { ApplicationCommandOptionType } from "discord.js";
import { CommandType, CommandObject, CommandUsage } from "wokcommands";

export default {
  description: "Adds numbers together",

  // Create a legacy and slash command
  type: CommandType.BOTH,

  // An array of
  // https://discord.js.org/#/docs/discord.js/main/typedef/ApplicationCommandOption
  options: [
    {
      name: "num1",
      description: "The first number",
      type: ApplicationCommandOptionType.Number,
      required: true,
    },
    {
      name: "num2",
      description: "The second number",
      type: ApplicationCommandOptionType.Number,
      required: true,
    },
  ],

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

    const sum = args.reduce((acc, cur) => {
      return acc + Number(cur);
    }, 0);

    return `The sum is ${sum}`;
  },
} as CommandObject;

The options array in this code snippet is similar to what WOKCommands will auto generate from the code in .

options
Inferred slash command arguments