Skip to content

Ability for buttons or menu items to fire events from where it is created #1795

Discussion options

You must be logged in to vote

This is not possible since events are dispatched from the gateway, that cannot be accessed by the button factory methods at all. If you want something like that you can make your own utility class which abstracts the listener filtering process for you, or use something like jda-ktx which offers the jda.onButton("id") { ... } handler.

You can always add a listener at runtime with JDA#addEventListener:

var button = Button.secondary("id", "Label");
event.getJDA().addEventListener(buttonListener("id", (e) -> ...)); // some custom listener code
event.getChannel().sendMessage("Click the button").setActionRow(button).queue(); // send the button

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@JustRed23
Comment options

Answer selected by JustRed23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants