Multiple Arguments

Let's write a command that receives two arguments:

  • firstParcel
  • secondParcel

And returns firstParcel * secondParcel.

Writing the MultiplyCommand#

It'll look like this:

path/to/your/app/src/Commands/MultiplyCommand.ts
import { Command, BaseCommand, Argument } from "discapp";
@Command()
export class MultiplyCommand extends BaseCommand {
@Argument()
public firstParcel: number;
@Argument()
public secondParcel: number;
public execute() {
return firstParcel * secondParcel;
}
}

Declaring arguments is just as simple as defining a property and marking them with @Argument().

tip

By assigning the type number to an argument, Discapp will guarantee that the argument is a number (1, 2) and not a string ('1', '2').

We will also alert the user if he sents a string but a number was expected.

Testing MultiplyCommand#

Since we did not explicitly defined a code for MultiplyCommand, Discapp automatically assigned the code multiply to it.

So we can test our command by sending the following message in our Discord server:

!multiply 5 4

Output should be 20.