Ability for buttons or menu items to fire events from where it is created #1795
-
So I've had my issues with buttons for a while. I always need to send the specific button id with everything i need to be picked up by the Example: I don't know if this would be a good idea but i have implemented that into my bot and it works fine. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I will link my version here so you can check out what i mean. |
Beta Was this translation helpful? Give feedback.
-
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 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 |
Beta Was this translation helpful? Give feedback.
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: