Skip to content

Argument

Gellért Dániel edited this page Dec 15, 2021 · 16 revisions

Arguments are like words in a sentence. After the command every space is the beginning of an argument.

For example:

/command argument1 argument2 argument3

Adding arguments to command

Discord allows you to specify multiple opportunities for one argument. This is useful when the command has multiple functionality. Multiple arguments can be specified for each index that the user can choose from.

To add argument to the command: Command#addArgument(Argument)

Command is like a tree. Every argument is a branch of the tree. Arguments with SUB_COMMAND and SUB_COMMAND_GROUP can have more branches (aka arguments), but not every type of arguments. Argument can be added to sub commands with SubArgument#addArgument(Argument)

Sub arguments

According to Discord's limitations, not every type of argument can hold any type of argument. In JCommands there are 2 types of argument that can hold other arguments:

Argument Accepted type of arguments
GroupArgument ConstantArgument
ConstantArgument InputArgument

Example

In the following example there is a command that has two different arguments. In the second argument the user can choose between the two different values.

GroupArgument groupArgument = new GroupArgument("which", "Which one do you want?");
groupArgument.addArgument(new ConstantArgument("this", "This is this"));
groupArgument.addArgument(new ConstantArgument("that", "This is that"));
command.addArgument(groupArgument);

Valid usage of the command with the arguments: /command which this and /command which that

Example