【问题标题】:"The application did not respond" after it sent the message JDA发送消息 JDA 后“应用程序没有响应”
【发布时间】:2022-08-16 20:56:04
【问题描述】:

所以我试图制作一个只发送嵌入的命令。它可以工作,但在使用命令后并在它已经发送嵌入后显示“应用程序没有响应”的东西!

这就是它在 Discord 中的样子

@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;
}
  • 交互需要在 3 秒内明确响应。 This 可能是您正在寻找的。

标签: java discord discord-jda


【解决方案1】:

像这样的交互需要你承认他们。否则,Discord 不知道您是否成功处理了它。

要确认斜线命令交互,您可以在事件上使用replydeferReply

您应该始终使用这些方法进行回复,而不是向频道发送消息。即使您的机器人无权在频道中发送消息,也可以使用斜杠命令,但它们仍然可以通过这些方法进行回复。

我强烈推荐阅读 JDA wiki 上的 interactions guide

长话短说,你必须用event.replyEmbeds(...) 替换你的event.getChannel().sendMessageEmbeds(...)。要添加按钮,您可以使用相同的方式在那里使用addActionRow

【讨论】:

    猜你喜欢
    • 2019-04-28
    • 1970-01-01
    • 2020-07-21
    • 2021-09-29
    • 2019-12-25
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    • 2011-03-16
    相关资源
    最近更新 更多