CzarnaWoda
CzarnaWoda

Reputation: 33

Button interaction failed

i have problem because i made smth in ButtonClickEvent and it works well but when someone click button under this button i have error "This interaction failed", i have to finish in code action with button or what can i do with this ?

Declaring button:

channel.sendFile(file,"paint.png").setEmbeds(embed.build()).setActionRow(Button.success("veryfication","VERYFI!")).queue();

And ButtonClickEvent:

public void onButtonClick(ButtonClickEvent e){
    if(e.getButton() != null) {
        if (e.getButton().getId().equalsIgnoreCase("veryfication")) {
            final Member member = e.getMember();
            if (member != null && member.getRoles() != null) {
                if (!member.getRoles().contains(e.getGuild().getRoleById("920701070831939669"))) {
                    e.getGuild().addRoleToMember(member, e.getGuild().getRoleById("920701070831939669")).queue();
                }
            }
        }
    }
}

Image:

Button error

Upvotes: 3

Views: 2087

Answers (1)

Minn
Minn

Reputation: 6131

Discord requires that you acknowledge the button interaction. This can be done with one of the following:

  • deferReply Reply with a "bot is thinking..." message and edit it later
  • reply Reply with a message
  • deferEdit Do nothing (or edit later)
  • editMessage Edit the message the button was clicked on

If you only want to acknowledge the button was clicked, without responding with a message or editing the message, you can simply use event.deferEdit().queue();.

Upvotes: 3

Related Questions