Select Menus
Tip
This section only covers how you define action components. You might also find the following resources useful:
- Replying with the Legacy Component System
- Components V2 Guide
- Component Utils
String Select Menus¶
String Select Menus are defined by annotating a method with @StringMenu
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 @MenuOption.
Example
Min & Max Value¶
String Select Menus support up to 25 options. You can set the minimum and maximum value by using the StringMenu#minValue() and StringMenu#maxValue()
fields.
Example
@SelectOption(label= "Pizza", value = "pizza")
@SelectOption(label= "Hamburger", value = "hamburger")
@SelectOption(label= "Sushi", value = "Sushi")
...
@StringMenu(value = "What's your favourite food?", minValue = 2, maxValue = 4)
public void onMenu(ComponentEvent event, List<String> choices) { ... }
Required¶
For Modals, you can also configure whether the user must populate the select menu. You can do this directly via the annotation. For example, you can have an optional select menu with the range set to [2 ; 5], meaning you accept either 0 options, or, at least 2 but at most 5.
Example
Entity Select Menus¶
Entity Select Menus are defined by annotating a method with @EntityMenu.
The first parameter must always be a ComponentEvent.
The second parameter must be of type Mentions.
Example
Channel Types¶
When using EntitySelectMenu.SelectTarget#CHANNEL you can limit the selectable channel types with the EntityMenu#channelTypes() field.
Example
Default Values¶
You can set the default values
of the Entity Select Menu by using respectively the EntityMenu#defaultChannels(), EntityMenu#defaultRoles() or EntityMenu#defaultUsers() fields.
Example
Min & Max Value¶
Just as for String Select Menus you can set the minimum and maximum value by using the EntityMenu#minValue() and EntityMenu#maxValue() fields.
Required¶
Again, this is handled the same way as with String Select Menus.
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)
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.