如何对嵌入消息JDA做出反应 [英] How to add reaction to an embed message JDA

查看:83
本文介绍了如何对嵌入消息JDA做出反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行命令〜verify时,我正在尝试发送和嵌入消息,然后它发送了一条嵌入消息,但我找不到在其中添加反应的方法。

I'm trying to send and embed message when I do the command ~verify and then it sends an embed message and I cant find how to add to there a reaction.

我已经完成了嵌入消息的发送,但是可以添加响应

I did already the embed message and sent it but can add the reaction


import Main.Bot;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;

import java.awt.*;

public class Verify extends ListenerAdapter {



    @Override
    public void onGuildMessageReceived(GuildMessageReceivedEvent e){
        if(e.getAuthor().isBot()) return;

        if(e.getMessage().getContentRaw().equalsIgnoreCase(Bot.prefix+"verify")){
            EmbedBuilder embedBuilder = new EmbedBuilder();
            embedBuilder.setColor(Color.red);
            embedBuilder.setTitle("Verify yourself!");
            embedBuilder.addField("How?","Press the ✔ reaction to verify",false);
            embedBuilder.setFooter("Created by SlayZBro#3501",e.getGuild().getIconUrl());

            e.getChannel().sendTyping().queue();
            e.getChannel().sendMessage(embedBuilder.build()).queue();
            embedBuilder.clear();


        }
    }


}

我需要将响应添加到嵌入消息中

I need to add the reaction to the embed message

推荐答案

您可以访问已发送邮件消息在 queue()的回调中添加,并在其中添加反应:

You can access the sent message in the callback for queue() and add reactions there:

channel.sendMessage(embed).queue(message -> message.addReaction(reaction).queue());

要添加多个问题,可以使用多行lambda:

To add multiple questions you can use a multiline lambda:

channel.sendMessage(embed).queue(message -> {
  message.addReaction(reaction1).queue();
  message.addReaction(reaction2).queue();
  message.addReaction(reaction3).queue();
});

也没有理由清除 EmbedBuilder ,因为它不会在您的代码中再次使用。生成器通常不是需要关闭/清除的资源,除非您再次使用它们并且不希望以前的设置。

Also there is no reason to clear the EmbedBuilder because it won't be used again in your code. Builders are usually not resources that need to be closed/cleared unless you use them again and don't want the previous settings.

这篇关于如何对嵌入消息JDA做出反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆