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
slash
optiontype
is a command option to define what the command can be used for. The only options available are:
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.
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