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
1
module.exports = {
2
// Best practice for the built-in help menu
3
category: 'Math',
4
description: 'Adds two numbers together',
5
6
// For the correct usage of the command
7
expectedArgs: '<number1> <number2>',
8
minArgs: 2,
9
maxArgs: 2,
10
syntaxError: 'Incorrect usage! Please use "{PREFIX}add {ARGUMENTS}"',
11
12
// Invoked when the command is actually ran
13
callback: ({ channel, args }) => {
14
// Convert the arguments into numbers
15
const number1 = parseInt(args[0])
16
const number2 = parseInt(args[1])
17
18
const sum = number1 + number2;
19
20
// Reply with the sum
21
channel.send({
22
content: `The sum is ${sum}`
23
})
24
25
// Alternatively we can just simply return our text
26
// WOKCommands will handle the proper way to reply with it
27
return `The sum is ${sum}`
28
}
29
}
Copied!
add.ts
1
import { ICommand } from 'wokcommands'
2
3
export default {
4
// Best practice for the built-in help menu
5
category: 'Math',
6
description: 'Adds two numbers together',
7
8
// For the correct usage of the command
9
expectedArgs: '<number1> <number2>',
10
minArgs: 2,
11
maxArgs: 2,
12
syntaxError: 'Incorrect usage! Please use "{PREFIX}add {ARGUMENTS}"',
13
14
// Invoked when the command is actually ran
15
callback: ({ channel, args }) => {
16
// Convert the arguments into numbers
17
const number1 = parseInt(args[0])
18
const number2 = parseInt(args[1])
19
20
const sum = number1 + number2;
21
22
// Reply with the sum
23
channel.send({
24
content: `The sum is ${sum}`
25
})
26
27
// Alternatively we can just simply return our text
28
// WOKCommands will handle the proper way to reply with it
29
return `The sum is ${sum}`
30
}
31
} as ICommand
Copied!
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