Skip to content

Quick Start

Kaktushose edited this page Jan 31, 2022 · 4 revisions

After the Setup is done you can now go on and create your first command.

Starting the Framework

Start the framework by calling:

JDACommands.start(jdaInstance, Main.class);

You can also specify package(s) to exclusively scan:

JDACommands.start(jdaInstance, Main.class, "com.example.bot.commands");

Making a simple PingPong Command

This command will simply listen to !ping and will response with Pong!.

@CommandController
public class PingCommand {

    @Command(value="ping")
    public void onPing(CommandEvent event) {
        event.reply("Pong!");
    }

}

Making a Ban Command

This is a more advanced command. Our ban command needs to match some requirements:

  • the executor needs the BAN_MEMBERS permission
  • members that have the role admin may not be banned
  • specify the history of messages, in days, that will be deleted. This value may not be greater than 7
  • optional: pass a reason
@CommandController
@Permission("BAN_MEMBERS")
public class BanCommand {

    @Command(value="ban")
    public void ban(CommandEvent event, @NotRole("admin") Member member, @Max(7) int delDays, @Optional @Concat String reason) {
      event.getGuild().ban(member, delDays, reason).queue();
      event.reply("%s got banned for reason %s", member.getAsMention(), reason);
    }
}

As seen above, JDA-Commands makes it possible to focus only on the business logic inside your command classes. All other chores like permission checks, argument parsing and validation, cooldowns, etc. are dealt with on the site of the framework.

If you don't want to use the argument parsing and validation, simply use a String array after the CommandEvent parameter.

@Command("label")
public void foo(CommandEvent event, String[] args) {...}

Important

This wiki is the documentation for V3 (text commands)! If you're using V4 (interactions) please refer to the new documentation

Home

Getting Started

Writing Commands

Advanced Configuration

Util

Clone this wiki locally