Skip to content

Instantly share code, notes, and snippets.

@zekroTJA

zekroTJA/readme.md

Last active May 17, 2021
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@PermissionError PermissionError commented Jun 22, 2018

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

@LizAinslie

This comment has been minimized.

Copy link

@LizAinslie LizAinslie commented Sep 19, 2019

@LeftistTachyon

This comment has been minimized.

Copy link

@LeftistTachyon LeftistTachyon commented Dec 1, 2019

@0ddlyoko

This comment has been minimized.

Copy link

@0ddlyoko 0ddlyoko commented Jan 12, 2020

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

This comment has been minimized.

Copy link

@survivorhd survivorhd commented Jun 26, 2020

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

@Meyssam120

This comment has been minimized.

Copy link

@Meyssam120 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());

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