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";exportdefault { 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";exportdefault { 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, }; },} asCommandObject;
When running /ping it will send "pong" in the same channel.
All of the normal WOKCommands callback arguments are available aside from message. A full list can be found here.
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 }) => {constnum1=parseInt(args[0])constnum2=parseInt(args[1])if (interaction) {interaction.reply({ content:String(num1 + num2), }) } },}