Making good looking button interactions is tedious - Feature request(?) #2452
neomoth
started this conversation in
Feedback & Suggestions
Replies: 1 comment
-
This is a limitation imposed by the Discord API. The API requires you to always replace all components in an edit request. Thus, we cannot offer this directly on a button instance, since it would require linking all other components, the message id, and the channel id to each button. However, when you do have the actions rows of a message, you can use LayoutComponent#updateComponent to edit individual components. For example: List<LayoutComponent> components = new ArrayList<>(message.getComponents());
components.updateComponent("help_close", Button.primary("help_close", Emoji.fromFormatted("<:xblock:1099425478105903274>")).asDisabled());
message.editMessageComponents(components).queue(); To disable all components you can also use LayoutComponent#asDisabled: List<LayoutComponent> components = message.getComponents().stream().map(LayoutComponent::asDisabled).toList();
message.editMessageComponents(components).queue(); Finally, in your code you can create your button list once like this: // Always the same control buttons, you can also move this into a separate method to make code more readable
btns.add(Button.primary("help_prev_page", Emoji.fromUnicode("⬅️")));
btns.add(Button.primary("help_close", Emoji.fromFormatted("<:xblock:1099425478105903274>")));
btns.add(Button.primary("help_next_page", Emoji.fromUnicode("➡️")));
// Conditionally disable some
if (page-1==0) {
btns.set(0, btns.get(0).asDisabled());
}
if (page+1==max) {
btns.set(2, btns.get(2).asDisabled());
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Allow me to explain. Lets say you're trying to make a help command that displays all available commands as well as their syntax and descriptions. After adding a lot of commands this would become a considerably long message to send. A good way to deal with this would be to have button interactions to flip between "pages" of commands to condense it down to 5 commands per "page". This is all fine and dandy until you run into issues where trying to go back a "page" would result in an array going out of bounds, the same being true for going forward a "page" when there are no commands left. It would make sense to disable the buttons rather than having to explicitly write code for an error that could just be avoided altogether right?
This is where my issue comes in, as far as I can tell there is no good method of editing any button in the action row apart from the button currently being interacted with. Even then, the only way I can disable the button is by creating an entirely new copy of the button with
.asDisabled()
at the end to make it disabled. This still requires access to.editButton()
, which is only available from getting the current interaction with.getInteraction()
.If I want to disable another button in the row, I quite literally have to copy and paste the creation of all the buttons used, and edit each to disable the buttons that shouldn't be available, which ends up looking like this:
You can see how this becomes tedious especially were there to be even more than three buttons. Either I'm missing a much better way to do this effect or no such method exists. I would have expected there to either been an
editButton()
method for theButton
object itself, or the ability to call something like.disable()
or.enable()
on a button to switch its state.Again maybe I'm missing something, but after doing my best to look through the docs as well as just experimenting with what I could find in my code, this was the only way I could come up with for doing what I wanted to do. If there is a better method of doing this, I'd love to hear it. If there isn't however, I'd like to know if there are plans to make this possible, because as it stands it's a very tedious thing to do.
(As a note, I put this in
Feedback and Suggestions
as opposed to theQuestions and Help
category as I'm unable to tell if I'm doing something incorrectly or if this is a feature that does not exist, in which case I think it should be added)Beta Was this translation helpful? Give feedback.
All reactions