Components¶
Note
This section only covers how you define components. See the Reply API section to learn how to use them in replies.
Buttons¶
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.
style¶
Sets the style of a button.
Example
Note
ButtonStyle.PREMIUM
is not supported by JDA-Commands.
emoji¶
Sets the emoji of a button.
link¶
Buttons that have a link cannot be executed, but they are still defined like normal buttons.
Example
Select Menus¶
String Select Menus¶
String Select Menus are defined by annotating a method with @StringSelectMenu
.
The first parameter must always be a ComponentEvent
.
The second parameter must be a List
.
The placeholder and other metadata of the String Select Menu is passed to the annotation.
Select Options are defined by annotating the method with
@SelectOption
.
Example
Min & Max Value¶
String Select Menus support up to 25 options. You can set the minimum and maximum value by using the minValue
and
maxValue
fields.
Example
@SelectOption(label= "Pizza", value = "pizza")
@SelectOption(label= "Hamburger", value = "hamburger")
@SelectOption(label= "Sushi", value = "Sushi")
...
@StringSelectMenu(value = "What's your favourite food?", minValue = 2, maxValue = 4)
public void onMenu(ComponentEvent event, List<String> choices) { ... }
Entity Select Menus¶
Entity Select Menus are defined by annotating a method with @EntitySelectMenu
.
The first parameter must always be a ComponentEvent
.
The second parameter must be of type Mentions
.
Example
Channel Types¶
When using SelectTarget.CHANNEL
you can limit the selectable channel types with the channelTypes
field.
Example
Default Values¶
You can set the default values
of the Entity Select Menu by using respectively the defaultChannels
, defaultRoles
or defaultUsers
fields.
Example
Min & Max Value¶
Just as for String Select Menus you can set the minimum and maximum value by using the minValue
and maxValue
fields.