How to add reaction to an embed message JDA

风流意气都作罢 提交于 2019-12-11 15:09:56

问题


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


回答1:


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

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

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.




回答2:


I understood how to do it. Just need to add this line

 e.getChannel().sendMessage(embedBuilder.build()).complete().addReaction("✔").queue();


来源:https://stackoverflow.com/questions/56761174/how-to-add-reaction-to-an-embed-message-jda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!