JDAButton Listener
Declares this function as a button 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 PersistentButtonBuilder.bindWith, however, it can be omitted if you use the type-safe bindWith extensions.
First parameter must be ButtonEvent.
Option types
User data: Uses @ComponentData, the order must match the data passed when creating the button, 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 SlashTypeSafeButtons(private val buttons: Buttons) : ApplicationCommand() {
@JDASlashCommand(name = "type_safe_buttons", description = "Demo of Kotlin type-safe bindings")
suspend fun onSlashTypeSafeButtons(event: GuildSlashEvent, @SlashOption argument: String) {
val button = buttons.primary("Click me").persistent {
bindTo(::onTestClick, argument)
}
event.replyComponents(button.into()).await()
}
@JDAButtonListener // No need for a name if you use the type-safe bindTo extensions
suspend fun onTestClick(event: ButtonEvent, @ComponentData argument: String) {
event.reply_("The argument was: $argument", ephemeral = true).await()
}
}