Skip to content

Instantly share code, notes, and snippets.

@zekroTJA
Last active July 28, 2023 18:51
Show Gist options
  • Select an option

  • Save zekroTJA/c8ed671204dafbbdf89c36fc3a1827e1 to your computer and use it in GitHub Desktop.

Select an option

Save zekroTJA/c8ed671204dafbbdf89c36fc3a1827e1 to your computer and use it in GitHub Desktop.
How to build an embed Builder in JDA

Required Imports

import net.dv8tion.jda.core.EmbedBuilder;
import java.awt.Color;

Build the EmbedBuilder

// Create the EmbedBuilder instance
EmbedBuilder eb = new EmbedBuilder();

/*
    Set the title:
    1. Arg: title as string
    2. Arg: URL as string or could also be null
 */
eb.setTitle("Title", null);

/*
    Set the color
 */
eb.setColor(Color.red);
eb.setColor(new Color(0xF40C0C));
eb.setColor(new Color(255, 0, 54));

/*
    Set the text of the Embed:
    Arg: text as string
 */
eb.setDescription("Text");

/*
    Add fields to embed:
    1. Arg: title as string
    2. Arg: text as string
    3. Arg: inline mode true / false
 */
eb.addField("Title of field", "test of field", false);

/*
    Add spacer like field
    Arg: inline mode true / false
 */
eb.addBlankField(false);

/*
    Add embed author:
    1. Arg: name as string
    2. Arg: url as string (can be null)
    3. Arg: icon url as string (can be null)
 */
eb.setAuthor("name", null, "https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/zekroBot_Logo_-_round_small.png");

/*
    Set footer:
    1. Arg: text as string
    2. icon url as string (can be null)
 */
eb.setFooter("Text", "https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/zekroBot_Logo_-_round_small.png");

/*
    Set image:
    Arg: image url as string
 */
eb.setImage("https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/logo%20-%20title.png");

/*
    Set thumbnail image:
    Arg: image url as string
 */
eb.setThumbnail("https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/logo%20-%20title.png");

Send the EmbedBuilder as message

//You need to build it to a string with ".build()" or it wont work.
channel.sendMessage(eb.build()).queue();
@PermissionError
Copy link

You're not actually building it to a String but a MessageEmbed Object - consider changing that, please

@LizAinslie
Copy link

@LeftistTachyon
Copy link

@0ddlyoko
Copy link

I just add this link here if you want more informations on how it'll be:
https://raw.githubusercontent.com/DV8FromTheWorld/JDA/assets/assets/docs/embeds/07-addField.png

@survivorhd
Copy link

survivorhd commented Jun 26, 2020

how can i add a reaction to this Embed?
@PermissionError

@Meyssam120
Copy link

Meyssam120 commented Jun 27, 2020

@survivorhd You can just react to the message to which the Embed is attached.
e.g.: channel.sendMessage(eb.build()).queue(message -> message.addReaction(YOUR_REACTION).queue());

@Splayfery
Copy link

Is it possible to send multiple embeds in one message?

@LasseR15
Copy link

@Splayfery since version 4.4.0 of JDA you can send up to 10 embeds with messageChannel.sendMessageEmbeds(embed1, embed2);
JDoc for reference

@Brokeos
Copy link

Brokeos commented Dec 15, 2021

Is it possible to send normal text (like @Mention) with an Embed ?
Like in Discord JS 13 :

https://stackoverflow.com/questions/64038253/how-to-put-both-normal-text-and-embed-in-the-same-message-discord-js

@LasseR15
Copy link

LasseR15 commented Dec 15, 2021

@Brokeos Yeah this is possible. I've done this with messageChannel.sendMessage("Test").setEmbeds(eb.build()).complete();
If you want to mention someone (in this example a role) you have to replace the "Test" with something like "<@&918236396496510986>" (a good chart for this)

@TheBlazer1607
Copy link

TheBlazer1607 commented Jan 23, 2022

message.getChannel().sendMessageEmbeds(info.build()).queue();
This works fine for me atleast.
(info is the name of the embed)

@LaFriska
Copy link

LaFriska commented Jun 3, 2022

how can i add a reaction to this Embed? @PermissionError

You add it when you are sending the message, not to the MessageEmbed object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment