JDAButtonListener

@Target(allowedTargets = [AnnotationTarget.FUNCTION])
annotation class JDAButtonListener(val name: String = "")(source)

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

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()
}
}

See also

@Aggregate

@Cooldown

@RateLimit

Properties

Link copied to clipboard
@get:JvmName(name = "value")
val name: String

Name of the button listener, referenced by PersistentButtonBuilder.bindTo.