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:

import { CommandType } from "wokcommands";

module.exports = {
  description: "Adds numbers together",
  type: CommandType.BOTH,

  minArgs: 2,
  maxArgs: 2,
  expectedArgs: "<num1> <num2>",

  callback: ({ args }) => {
    const sum = args.reduce((acc, cur) => {
      return acc + Number(cur)
    }, 0)

    return `The sum is ${sum}`

If the user runs !add or !add 5 your bot will respond with Correct syntax: !add <num1> <num2>. If the user runs !add 5 10 it will then respond with The sum is 15.

Last updated