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

Slash commands

Slash commands are a new system for commands within Discord bots. WOKCommands aims to help developers implement slash commands in the easiest way possible.

Here is a basic ping pong slash command example:

ping.js
import { CommandType } from "wokcommands";

export default {
  description: "Ping pong command",

  // Only create a slash command, not a legacy command
  // You can also use "CommandType.BOTH" to create a
  // legacy and slash command
  type: CommandType.SLASH,

  callback: () => {
    return {
      content: "Pong!",
      ephemeral: true,
    };
  },
};
ping.ts
import { CommandObject, CommandType } from "wokcommands";

export default {
  description: "Ping pong command",

  // Only create a slash command, not a legacy command
  // You can also use "CommandType.BOTH" to create a
  // legacy and slash command
  type: CommandType.SLASH,
  
  callback: () => {
    return {
      content: "Pong!",
      ephemeral: true,
    };
  },
} as CommandObject;

When running /ping it will send "pong" in the same channel.

Using your own Options for Slash Commands

Sometimes you may want to pass in your own options object to your slash command. You can easily do so by passing in an options property to your command like so:

add.js
module.exports = {
  category: 'test', // Required for the slash commands
  description: 'Adds two numbers', // Required for the slash commands

  slash: true, // If options are given then slash must be either true or 'both'
  testOnly: true, // Ensure you have test servers setup

  options: [
    {
      name: 'num1', // Must be lower case
      description: 'The first number.',
      required: true,
      type: 'STRING',
    },
    {
      name: 'num2', // Must be lower case
      description: 'The second number.',
      required: true,
      type: 'STRING',
    },
  ],
  callback: ({ interaction, args }) => {
    const num1 = parseInt(args[0])
    const num2 = parseInt(args[1])

    if (interaction) {
      interaction.reply({
        content: String(num1 + num2),
      })
    }
  },
}
add.ts
PreviousRequired permissionsNextInferred slash command arguments

Last updated 1 year ago

Was this helpful?

All of the normal WOKCommands callback arguments are available aside from message. A full list can be found .

here