nocli-handler.js
  • ๐Ÿ”—Links
    • Link to NPM Package
    • Link to Github Package
  • ๐Ÿš€Introduction
    • Welcome
    • Changelog
  • ๐ŸงชGetting Started
    • Setting Up Your Project
  • โ“Guides
    • Instance
      • Providing a MongoDB Connection
      • Things you really need to know
    • Commands
      • Creating a simple "Ping Pong" Command
      • Command Arguments
      • Enabling Slash Commands
      • Deleting a Command
      • Guild and Owner-only Commands
      • Command Aliases
      • Deferring a command reply
      • Running Events inside a Command
      • Command Cooldowns
      • Setting up Autocomplete
      • Required Permissions
  • ๐ŸซClasses
    • NoCliHandler
      • .connectToMongoDB()
    • ChannelCommands
      • .action()
      • .add()
      • .remove()
      • .getAvailableChannels()
    • Command
    • CommandHandler
      • .getValidations()
      • .readFiles()
      • .runCommand()
      • .isCommand()
    • CustomCommands
      • .loadCommands()
      • .create()
      • .delete()
      • .run()
    • DisabledCommands
      • .loadDisabledCommands()
      • .disable()
      • .enable()
      • .isDisabled()
    • PrefixHandler
      • .loadPrefixes()
      • .get()
      • .set()
    • SlashCommands
      • .getCommands()
      • .findCommand()
      • .optionsAreDifferent()
      • .create()
      • .delete()
      • .createOptions()
    • EventHandler
      • .readFiles()
      • .registerEvents()
      • .isEvent()
  • ๐Ÿ› ๏ธUtilities
    • Cooldowns
      • .loadCooldowns()
      • .getKeyFromCooldownUsage()
      • .cancelCooldown()
      • .updateCooldown()
      • .verifyCooldown()
      • .getKey()
      • .canBypass()
      • .start()
      • .canRunAction()
    • handleCommandAutocomplete
    • handleError
    • log
    • getAllFiles
    • importFile
  • ๐Ÿ†ŽDefinitions
    • NoCliCategoryConfiguration
    • NoCliCategoryType
    • ICommand
    • CommandOptions
    • CommandCallbackOptions
    • NoCliCommandCooldown
    • NoCliCommandType
    • cooldownTypesArray
    • NoCliCooldownType
    • NoCliCooldownKeyOptions
    • IEvent
    • EventConfigurationOptions
    • DynamicValidationConfigurationOptions
    • DynamicValidationCheck
    • DynamicValidationCheckFunction
    • NoCliHandlerOptions
    • NoCliCooldownOptions
    • NoCliCooldownConfigOptions
    • MongoDBConnection
    • MongoDBResult
    • DebugOptions
    • ConfigOptions
    • ValidationPluginsOption
    • NoCliEmojiConfigOptions
    • NoCliLanguageType
    • NoCliRuntimeValidationType
    • NoCliSyntaxValidationType
Powered by GitBook
On this page
  • minArgs and maxArgs
  • What is expectedArgs?
  1. Guides
  2. Commands

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.

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

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.

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

add.js
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;
add.ts
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;

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.

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.

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

PreviousCreating a simple "Ping Pong" CommandNextEnabling Slash Commands

Last updated 2 years ago

โ“