JDA icon indicating copy to clipboard operation
JDA copied to clipboard

Message components cloning bug

Open Xlkki opened this issue 2 years ago • 0 comments

General Troubleshooting

  • [X] I have checked for similar issues on the Issue-tracker.
  • [X] I have updated to the latest JDA version
  • [X] I have checked the branches or the maintainers' PRs for upcoming bug fixes.

Expected Behaviour

I have a message generated using MessageCreateBuilder with components. They should be disabled depending on a number of conditions, but in order to keep these components unchanged in the original message, I create a copy of it using the MessageCreateBuilder.from(original) method. I get a builder with a duplicate of the original message, which I can modify for my needs, but the components of this builder and the original message are linked, and if I change them in the copy using the LayoutComponent.updateComponent(copy.getComponents(), someId, newComponent) method, it will also change in the original message.

I showed an example of this in the screenshot. image

I created a message with a button and sent it. Then I created a copy of this message, replaced the button with its disabled copy, and sent it. After all that, I sent the original message again, but it also replaced the button with a disabled copy

Code Example for Reproduction Steps

public void someMethod(JDA jda, TextChannel channel) {
        Button originalButton = Button.of(ButtonStyle.SECONDARY, "some-button", "Test");
        MessageCreateData original = new MessageCreateBuilder()
                .setContent("Original message")
                .setActionRow(originalButton)
                .build();

        channel.sendMessage(original).queue();

        MessageCreateData copy = MessageCreateBuilder.from(original).setContent("Copied message").build();
        LayoutComponent.updateComponent(copy.getComponents(), "some-button", originalButton.asDisabled());

        channel.sendMessage(copy).queue();        
        channel.sendMessage(original).queue();
}

Code for JDABuilder or DefaultShardManagerBuilder used

JDABuilder builder = JDABuilder.createDefault("some-token");

Exception or Error

No response

Xlkki avatar Sep 01 '22 09:09 Xlkki