WOKCommands
Search…
Correct argument usage
You can specify the exact arguments and the minimum/maximum number of arguments for each command. If the user provides an incorrect number of arguments then WOKCommands will automatically tell them the correct usage based off of the command properties you provided. Here is an example:
JavaScript
TypeScript
add.js
module.exports = {
// Best practice for the built-in help menu
category: 'Math',
description: 'Adds two numbers together',
// For the correct usage of the command
expectedArgs: '<number1> <number2>',
minArgs: 2,
maxArgs: 2,
syntaxError: 'Incorrect usage! Please use "{PREFIX}add {ARGUMENTS}"',
// Invoked when the command is actually ran
callback: ({ channel, args }) => {
// Convert the arguments into numbers
const number1 = parseInt(args[0])
const number2 = parseInt(args[1])
const sum = number1 + number2;
// Reply with the sum
channel.send({
content: `The sum is ${sum}`
})
// Alternatively we can just simply return our text
// WOKCommands will handle the proper way to reply with it
return `The sum is ${sum}`
}
}
add.ts
import { ICommand } from 'wokcommands'
export default {
// Best practice for the built-in help menu
category: 'Math',
description: 'Adds two numbers together',
// For the correct usage of the command
expectedArgs: '<number1> <number2>',
minArgs: 2,
maxArgs: 2,
syntaxError: 'Incorrect usage! Please use "{PREFIX}add {ARGUMENTS}"',
// Invoked when the command is actually ran
callback: ({ channel, args }) => {
// Convert the arguments into numbers
const number1 = parseInt(args[0])
const number2 = parseInt(args[1])
const sum = number1 + number2;
// Reply with the sum
channel.send({
content: `The sum is ${sum}`
})
// Alternatively we can just simply return our text
// WOKCommands will handle the proper way to reply with it
return `The sum is ${sum}`
}
} as ICommand
If the user runs !add or !add 5 your bot will respond with Incorrect usage! Please use !add <Number 1> <Number2>. If the user runs !add 5 10 it will then respond with The sum is 15.
Copy link