简体   繁体   中英

"The application did not respond" after it sent the message JDA

So im trying to make a command that just sends an embed. It works but it shows the "The application did not respond" thing after using the Command and after it has already sent the embed!

This is how it looks in Discord

1

@Override
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
    String roles = String.valueOf(event.getMember().getRoles());
        if (event.getName().equals("whosthatpokemon")) {
            Color relaxo = new Color(44, 106, 124);
            EmbedBuilder embed = new EmbedBuilder();
            embed.setColor(relaxo);
            embed.setTitle("Who's that Pokemon?");
            embed.setDescription("Who is it?");
            embed.setImage("http://cdn.poll-maker.com/7-375248/snorlax.png?sz=1200-000000100053");
            event.getChannel().sendMessageEmbeds(embed.build()).setActionRow(sendButtons()).queue();
        }
    }
private static java.util.List<Button> sendButtons() {

    List<Button> buttons = new ArrayList<>();
    buttons.add(Button.danger("Snorlax", "Snorlax"));
    buttons.add(Button.success("Pickachu", "Pickachu"));
    buttons.add(Button.primary("Bulbasaur", "Bulbasaur"));

    return buttons;
}

Interactions like this require that you acknowledge them. Otherwise, Discord doesn't know you handled it successfully.

To acknowledge a slash command interaction, you can use reply or deferReply on the event.

You should always reply using these methods instead of sending messages to the channel. Slash commands can be used even when your bot doesn't have permissions to send messages in the channel, they can still reply through these methods though.

I would highly recommend reading the interactions guide on the JDA wiki.

Long story short, you have to replace your event.getChannel().sendMessageEmbeds(...) with event.replyEmbeds(...) . To add buttons, you can use addActionRow on there the same way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM