Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Additional Annotations

Kevin edited this page Oct 9, 2023 · 1 revision

BotUser

Used on a command parameter to mark a User or Member parameter to be represented by the bot's User or Member object.

@CommandAlias("bot")
public void onCommand(JavacordCommandEvent event, @BotUser Member member) {
    // Replies with the bot's display name within the server
    event.reply(member.getDisplayName());
}

Choices

Used on parameters of slash commands to predefine the options for a specific parameter.

@Subcommand("stringchoice")
@Description("Pick a choice.")
public void onStringchoice(SlashCommandEvent event,
                     @Description("Your choice.") @Choices("test1=one,test2=two,test3=three") String message) {
    event.newImmediateResponse()
            .setContent(message) // Will send "one" if "test1" is selected, "two" if "test2" is selected, etc.
            .respond();
}

CommandOptions

Used on a root slash command to change specific types of options for the command. The following options are available:

  • Marking a command as enabled for everyone by default (default is true);
  • Marking a command as enabled for everyone that has any type of specific PermissionType (default is none);
  • Marking a command as disabled by default (default is false);
  • Marking a command as enabled in DMs (default is true);
  • Marking a command as age-restricted (default is false);

The following is an example of an age-restricted command.

@CommandAlias("nsfw")
@Description("An age-restricted command.")
@CommandOptions(isNsfw = true)
public class NsfwSlashCommand extends BaseCommand {

    @Default
    public void onCommand() {
        // Do something
    }
}

CrossServer

Used on a command parameter to allow resolving the parameter globally (all of the servers the bot is connected to). This can be used for any server channel type (ServerTextChannel, ServerVoiceChannel etc.), as well as on Role.

Issuer

Used on a User or Member command parameter to retrieve the user/member that invoked the command.

@CommandAlias("user")
public void onCommand(JavacordCommandEvent event, @Issuer User user) {
    // Sends the user's name
    event.reply(user.getName());
}

ServerCommand

Used to mark a slash command to be registered for a specific server instead of globally. You can pass either a server's ID or name to the annotation.

@CommandAlias("command")
@Description("A command exclusive to a specific server.")
@ServerCommand(name = "Your Server")
//@ServerCommand(id = 1234567890L) - Use this instead if you want to use a server's ID instead of its name
public class ServerSlashCommand extends BaseCommand {

    @Default
    public void onCommand() {
        // Do something
    }
}