JDASelect Menu Listener
Declares this function as a select menu listener with the given name.
Requirements
The declaring class must be annotated with @Handler or @Command.
The annotation value to have same name as the one given to IPersistentActionableComponent.bindTo, however, it can be omitted if you use the type-safe bindWith extensions.
First parameter must be StringSelectEvent/EntitySelectEvent.
Option types
User data: Uses @ComponentData, the order must match the data passed when creating the select menu, supported types and modifiers are in ParameterResolver, additional types can be added by implementing ComponentParameterResolver.
Custom options: No annotation, additional types can be added by implementing ICustomResolver.
Service options: No annotation, however, I recommend injecting the service in the class instead.
Type-safe bindings in Kotlin
You can use the bindWith extensions to safely pass data, in this case you don't need to set the listener name:
@Command
class SlashTypeSafeSelectMenus(private val selectMenus: SelectMenus) : ApplicationCommand() {
@JDASlashCommand(name = "type_safe_select_menus", description = "Demo of Kotlin type-safe bindings")
suspend fun onSlashTypeSafeSelectMenus(event: GuildSlashEvent, @SlashOption argument: String) {
val selectMenu = selectMenus.entitySelectMenu(EntitySelectMenu.SelectTarget.ROLE).persistent {
bindTo(::onTestSelect, argument)
}
event.replyComponents(selectMenu.into()).await()
}
@JDASelectMenuListener // No need for a name if you use the type-safe bindTo extensions
suspend fun onTestSelect(event: EntitySelectEvent, @ComponentData argument: String) {
event.reply_("The argument was: $argument", ephemeral = true).await()
}
}
See also
Properties
Name of the select menu listener, referenced by IPersistentActionableComponent.bindTo.