Enabling Slash Commands

Slash commands are commands registered from a bot to Discord with the "/" prefix for those who are not used to legacy (or text) commands.

Using slash option

type is a command option to define what the command can be used for. The only options available are:

This option is not required, so when you do not specify this option, the command will be a legacy command. So ยฏ\_(ใƒ„)_/ยฏ

On the first page of the Commands Guide, we learned how to create our very own ping command (which is a legacy command). So let's use that as an example of creating a Slash Command.

ping.js
const { NoCliCommandType } = require("nocli-handler.js");

/**
 * @type {import("nocli-handler.js").ICommand}
 */
const Command = {
    description: "Checks client latency",
    type: NoCliCommandType.Both, // <-- Set the command type here (optional)
    callback: ({ client, message, args, text }) => {
        return `๐Ÿ“ Pong! \`${client.ws.ping}ms\``
    }
}

module.exports = Command;

Once done, run the program, and let's try running the "ping" command. Here's what it will appear:

Legacy Command:

Slash Command:

Last updated