Skip to content

Annotations

MrFrydae edited this page Sep 13, 2023 · 2 revisions

AutoCompletion

  • On parameters to provide Discord with autocompletion values
  • Must register completion values before they can be used

CommandAlias

  • On the Class itself to define the base commands for all sub commands defined
  • On Subcommands to define aliases for the subcommand as root commands. Example if your command is /foo bar then adding a @CommandAlias("fb") makes /fb the same as /foo bar.

CommandPermission

  • Placed on a sub/command to restrict access
  • Value of this command are elements of the Permission enum.

Name

  • Must be included on every parameter.
  • Changes the display name of a parameter

Description

  • Must be included on every parameter and command method.
  • Changes the description of a parameter or command

Subcommand

  • Defines a subcommand on a Command class

GlobalCommand

  • Can be added to a command
  • Allowes for commands to be sent in DMs with the bot

Examples

Ping

This code creates a command /ping which replied with a hidden message. Since it is a GlobalCommand, it can be sent in both a text channel, and a private message. Note: Commands don't need parameters.

@CommandAlias("ping")
@Description("Pong!")
@GlobalCommand
public void onPing() {
    replyHidden(":ping_pong: Pong!").queue();
}

image

Mirror

This creates a command /mirror which duplicates a message into another channel. This command requires the user to have the Manage Messages permission to execute it.

@CommandAlias("mirror")
@Description("Mirror a message into another channel")
@CommandPermission(Permission.MESSAGE_MANAGE)
public void onMirror(@Name("message") @Description("The ID of the message") String id,
                     @Name("channel") @Description("The channel you'd like to mirror to") TextChannel channel) {
    getEvent().getInteraction().deferReply(true).queue(hook -> {
        MessageChannel sentFrom = hook.getInteraction().getMessageChannel();

        sentFrom.retrieveMessageById(id)
                .onErrorFlatMap((error) -> hook.editOriginal(error.getMessage()))
                .onSuccess((message) -> {
                    String contentRaw = message.getContentRaw();

                    channel.sendMessage(contentRaw).queue();

                    hook.editOriginal("Message mirrored").queue();
                })
                .queue();
    });
}

image

image

image

Clone this wiki locally