Skip to content

Buttons

Tip

This section only covers how you define action components. You might also find the following resources useful:

Buttons are defined by annotating a method with @Button. The first parameter must always be a ComponentEvent. The label and other metadata of the button is passed to the annotation.

@Button("example")
public void onButton(ComponentEvent event) {...}

Style

Sets the style of a button.

Button Styles

Example

@Button(value = "example", style = ButtonStyle.DANGER)
public void onButton(ComponentEvent event) {...}

Note

ButtonStyle#PREMIUM is not supported by JDA-Commands.

Emoji

Sets the emoji of a button.

Example

@Button(value = "Emoji", emoji = "🤗")
public void onButton(ComponentEvent event) {...}

Buttons that have a link cannot be executed, but they are still defined like normal buttons.

Example

@Button(value = "JDA-Commands Wiki", link = "https://kaktushose.github.io/jda-commands/wiki/")
public void onButton(ComponentEvent event) { }

Localization and Emojis

To avoid hardcoded values, all string values of an annotation can be replaced by a localization key as supported by the current used Localization System.

Furthermore, it's possible to directly use placeholders. For more information on how to use placeholders please visit this page.

Also take a look at the general message resolution documentation.

Example (with Fluava)

@Button(value = "my.localization.key", style = ButtonStyle.DANGER, link = "{ $jdac_link }")
public void onButton(ComponentEvent event) {...}

The Dollar Sign ($)

The dollar sign is a reserved character for bundle name separation. In most cases that shouldn't bother you but if you encounter any problems, please read the notes here.

JDA-Commands has built in support for Unicode and application emoji aliases. If you want to use them, just take a look here.