> For the complete documentation index, see [llms.txt](https://tribui141108.gitbook.io/nocli-handler.js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tribui141108.gitbook.io/nocli-handler.js/guides/commands/command-arguments.md).

# Command Arguments

Command arguments are options where the user inputs their data which can help when the bot is doing actions with the command.

### `minArgs` and `maxArgs`

`minArgs` (Minimum Arguments) and `maxArgs` (Maximum Arguments) help the bot to understand how many arguments can be placed by the user when running a command. There are helpful when specifying values with `expectedArgs`.

### What is `expectedArgs`?

`expectedArgs` (Expected Arguments) is used to specify the arguments' names, and there are also annotations which you will need to apply.

```javascript
["<", "arg_name", ">"] // Required Arguments | Example: "<text>"
["[", "arg_name", "]"] // Optional Arguments | Example: "[text]"
```

{% hint style="warning" %}
If `minArgs` is not specified (or is set to 0), all of these arguments will be optional. So you might think these annotations might be pretty useless. However, these annotations are required, and they can help you understand which argument is required and which is not in your command. This also applies to Slash Commands as well.

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.
{% endhint %}

Let's create a new command "add" to show how arguments can be used in a command.

{% tabs %}
{% tab title="JavaScript" %}
{% code title="add.js" %}

```javascript
const { NoCliCommandType } = require("nocli-handler.js");

/**
 * @type {import("nocli-handler.js").ICommand}
 */
const Command = {
    type: NoCliCommandType.Legacy,
    description: "Adds numbers together and prints out the sum",
    testOnly: true,
    minArgs: 2,
    maxArgs: 3,
    expectedArgs: "<num1> <num2> [num3]",
    callback: ({ client, message, interaction, args, text }) => {
        let sum = 0;
        for (const arg of args) {
            sum += parseInt(arg);
        }
        return 'The sum is ' + sum;
    }
}

module.exports = Command;
```

{% endcode %}
{% endtab %}

{% tab title="TypeScript" %}
{% code title="add.ts" %}

```typescript
import { ICommand, NoCliCommandType } from "nocli-handler.js";

export default {
    type: NoCliCommandType.Legacy,
    description: "Adds numbers together and prints out the sum",
    testOnly: true,
    minArgs: 2,
    maxArgs: 3,
    expectedArgs: "<num1> <num2> [num3]",
    callback: ({ client, message, interaction, args, text }) => {
        let sum = 0;
        for (const arg of args) {
            sum += parseInt(arg);
        }
        return 'The sum is ' + sum;
    }
} as ICommand;
```

{% endcode %}
{% endtab %}
{% endtabs %}

This "add" command adds numbers together, meaning the first and second arguments are required. So we set minArgs to 2, and `num1` and `num2`  arguments will be wrapped in <>. Then, we will set maxArgs to the number of arguments specified in expectedArgs.

{% hint style="info" %}
Don't worry if you are not used to this. You can apply using options (if it seems easier to you). However, this only applies to Slash Commands.
{% endhint %}

Once done, run the program, and test it out.

![](https://2061993693-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxf3u6ixvplxDFSNlKMyF%2Fuploads%2FM9zbzEb1qmnjBzXCuuoX%2Fimage.png?alt=media\&token=7b20d3ae-1ca5-4cb2-a380-826ba58e975d)
