CommandArgument - Paultje52/SupaBotBase GitHub Wiki

NOTE: This code isn't available yet in the public release, only in the beta.

The CommandArgument class is more than just a class. It also exports CommandArgumentChoice and types.

With CommandArgument you can create easily readable and debuggable arguments for your commands. You can get to it by the property CommandArgument on SupaBotBase.

const { CommandArgument } = require("supabotbase");

The CommandArgumentChoice and types are properties of CommandArgument.

const { 
  CommandArgument, 
  CommandArgument: {CommandArgumentChoice, types: commandArgumentType} 
} = require("supabotbase");

CommandArgument

The CommandArgument class is chainable.

Constructor

Constructing this class requires one parameter, the argument type. It needs to be a number, but you can also use Types

setName

Sets the name of the argument. Parameter needs to be a string.

setDescription

Sets the description of the argument. Parameter needs to be a string.

setRequired

Set if the argument is required. Parameter needs to be a boolean.

setOptions

When setting a string this is optional. When setting a subcommand (group) this is required. The parameters can be CommandArgument or CommandArgumentChoice. Each new parameter is a new option.

Example

const { 
  CommandArgument, 
  CommandArgument: {CommandArgumentChoice, types: commandArgumentType} 
} = require("supabotbase");

// ...
// In a command constructor
this.setArgs(
  // First argument
  new CommandArgument(commandArgumentType.user)
    .setName("user")
    .setDescription("The target user")
    .setRequired(true),
  // Second argument
  new CommandArgument(commandArgumentType.string)
    .setName("action")
    .setDescription("An action for the user")
    .setRequired(true)
    .setOptions(
      // First choice
      new CommandArgumentChoice()
        .setName("Ban the user")
        .setValue("ban"),
      // Second choice
      new CommandArgumentChoice()
        .setName("Kick the user")
        .setValue("kick")
    )
);

CommandArgumentChoice

When setting the argument type to a string, you can add possible options via the CommandArgumentChoice. This class is chainable.

Constructor

Nothing special. You don't need extra arguments or something like that in the constructor.

setName

Sets the name, the part the user can see. Needs to be a string between 2 and 100 characters.

setValue

Sets the value, the part that your code receives. Needs to be a string between 2 and 100 characters.

Example

new CommandArgumentChoice()
  .setName("Ban the user") // What the user sees
  .setValue("ban") // what your code recieves

Types

There are a couple types for command arguments. Here is a list.

  • subCommand: You can put arguments in here.
  • subCommandGroup: You can put subCommands in here
  • string
  • integer
  • boolean
  • user
  • channel
  • role