Rich embed discord

Rich embed discord DEFAULT

Embeds might look nice but they can be disabled through permissions and user preferences, and will not look the same on mobile - especially complex ones. It's strongly recommended not to use them unless you have a text-only fallback. Yes they're nice, but, don't use them if you don't need to!

Here are a few rules for embeds:

  • Every field is optional
  • At least one field must be present
  • No field can be empty, null, or undefined.

Those aren't just guidelines, they are rules, and breaking those rules means your embed will not send - it will return .

There are 2 ways to do embeds. The cleanest way is by using the builder and the second is writing the object itself, we'll cover the builder first.

The same rules apply for as they do for object based ones. In fact, the builder is just a shortcut to get the same object and offers no more, no less functionality.

Which produces the following:

The example embed

Now doesn't that code look clean and amazing? Well let's look at the object version.

As you can see it's bit of a chonker in comparison, but they both output the same embed so there's no real reason to show it off, congratulations you know how to use embeds in normal messages now!

Not that it's any different if you're using a webhook, or an interaction response.

Edit this page

Sours: https://anidiots.guide/first-bot/using-embeds-in-messages

How to use

RichEmbed

function

in

js

Best JavaScript code snippets using discord.js.RichEmbed(Showing top 15 results out of 315)

new Discord.RichEmbed() .setColor(0xB1A0A8) .addField(`🎶 ▸ Playlist - **[\`${dT}\`]**`, `${serverQueue.soms.map(song => `**[\`${song.numero}\`] -** ${song.title}`).slice(0,10).join('\n')}\n\n`) .setFooter(`🔎 ▸ Página ${pagina} de ${totalPages}`, message.author.displayAvatarURL) .setTimestamp()
profileDB.findOne({ userID: message.author.id }, asyncfunction(err, doc) { const embed = new Discord.RichEmbed() .setTitle(message.author.username) .addField('Seu level é:', doc.level) .addField('Seu XP é:', doc.xp) .setColor(config.color); message.channel.send({ embed }); });
events.on('updateCheckItemStateOnCard', (event, board) => { if (event.data.checkItem.state === "complete") { if (!eventEnabled(`checklistItemMarkedComplete`)) returnlet embed = getEmbedBase(event) .setTitle(`Checklist item marked complete!`) .setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Checklist item under checklist \`${event.data.checklist.name}\` marked complete by **[${conf.realNames ? event.memberCreator.fullName : event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`) .addField(`Checklist Item Name`, event.data.checkItem.name.length > 1024 ? `${event.data.checkItem.name.trim().slice(0, 1020)}...` : event.data.checkItem.name) send(addDiscordUserData(embed, event.memberCreator)) } elseif (event.data.checkItem.state === "incomplete") { if (!eventEnabled(`checklistItemMarkedIncomplete`)) returnlet embed = getEmbedBase(event) .setTitle(`Checklist item marked incomplete!`) .setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Checklist item under checklist \`${event.data.checklist.name}\` marked incomplete by **[${conf.realNames ? event.memberCreator.fullName : event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`) .addField(`Checklist Item Name`, event.data.checkItem.name.length > 1024 ? `${event.data.checkItem.name.trim().slice(0, 1020)}...` : event.data.checkItem.name) send(addDiscordUserData(embed, event.memberCreator)) } })
function getArtistEmbed(msg, spotifyId, withPreview) { spotifyApi.getArtist(spotifyId) .then(data => { const apiResponse = data.body; const embed = new RichEmbed() .setColor([30, 215, 96]) .setThumbnail(apiResponse.images[0].url) .setAuthor('Click to listen on Spotify', 'https://image.flaticon.com/icons/png/512/174/174872.png', apiResponse.external_urls.spotify) .addField('Artist Name', apiResponse.name, true) .addField('Followers', apiResponse.followers.total.toLocaleString(), true) .addField('Popularity', apiResponse.popularity + '%', true) .addField('Genres', ((apiResponse.genres.length > 0) ? apiResponse.genres.join(', ') : 'unknown'), true); msg.edit({ embed }); if (withPreview) msg.channel.send(`Got spotify? Click below to play! ${apiResponse.external_urls.spotify}`); }).catch(err => { throw `Something went wrong! ${err}`; }); }
async run(message, args, level, settings, texts) { if (!args[0]) return message.channel.send(texts.cmd.info.noEmoji); if (args[0].startsWith("<a:")) return message.channel.send("This command does not support animated emojis yet."); if (args[0].charCodeAt(0) >= 55296) return message.channel.send(`${texts.cmd.info.regularEmoji.replace(/{{emoji}}/g, args[0])}\nhttps://twemoji.twitter.com`); const match = args[0].match(/<:[a-zA-Z0-9_-]+:(\d{18})>/); if (!match || !match[1]) return message.channel.send(texts.cmd.info.invalidEmoji); const emoji = this.client.emojis.get(match[1]); if (!emoji) return message.channel.send(texts.cmd.info.invalidEmoji); const embed = new RichEmbed() .setColor(2934736) .setTitle("Emoji Information") .setThumbnail(emoji.url) .addField("❯ Name", emoji.name, true) .addField("❯ ID", emoji.id, true) .addField("❯ Created", moment.utc(emoji.createdAt).format("DD/MM/YYYY"), true) .addField("❯ From", emoji.guild, true) .setFooter(`Info requested by ${message.author.tag}`, message.author.displayAvatarURL) .setTimestamp(); return message.channel.send({ embed }); }
node.find('span[data-dobid=hdw]').each((i, word) => { const root = node.find('span[data-dobid=hdw]').parent().parent(); const pronunciation = $(root).find('span.lr_dct_ph > span'); if(!pronunciation) returntrue; const select = (selector) => $(selector).parent().parent().parent().find('ol.lr_dct_sf_sens') .find('div.lr_dct_sf_sen.vk_txt') .find('div._Jig > div[data-dobid=dfn] > span'); const lexicalCategory = $(root).find('div.lr_dct_sf_h > i > span'); let defenitions = select(root); $(lexicalCategory).each((i, category) => { defenitions = select(category); try { let descrip = [`${$(category).text()}`]; $(defenitions).each((i, e) => { descrip.push(`${i + 1}. ${$(e).text()}`); }); if(i === 0) e.addField(`${$(word).text()} / ${$(pronunciation).text()}`, descrip.join('\n')); else e.addField(`${$(word).text()} / ${$(pronunciation).text()}`, descrip.join('\n')); } catch(e) { returntrue; } }); });
.setTitle(`Hey ${message.author.username}, I'm delet!`) .setDescription("I'm a bot developed and maintained by the DS Development Group.") .addField("Version", delet.version, true) .addField("Website", "https://delet.js.org", true) .addField("Users", this.client.users.size, true) .addField("Invite link", "[Click here](https://delet.js.org/go/invite)", true) .addField("Uptime", `${moment.utc(this.client.uptime).format("DD")-1} day(s), ${moment.utc(this.client.uptime).format("HH:mm:ss")}`, true) .addField("GitHub", "[Click here](https://github.com/DS-Development/delet)", true) .addField("Node.js version", process.version, true) .addField("Memory usage", `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`, true) .setFooter(`Made with Discord.js (v${version})`, "https://vgy.me/ZlOMAx.png") .setTimestamp();
new Discord.RichEmbed() .setColor(0xB1A0A8) .addField(`🎶 ▸ Playlist - **${serverQueue.duraTotal}**`, `${serverQueue.soms.map(song => `**[\`${song.numero}\`] -** ${song.title}`).slice(0,10).join('\n')}\n\n`) .setFooter(`🔎 ▸ Página ${pagina} de ${totalPages}`, message.author.displayAvatarURL) .setTimestamp()
events.on('commentCard', (event, board) => { let embed = getEmbedBase(event) if (event.data.hasOwnProperty("textData")) { if (!eventEnabled(`commentEdited`)) return embed .setTitle(`Comment edited on card!`) .setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Card comment edited (see below for comment text) by **[${conf.realNames ? event.memberCreator.fullName : event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`) .addField(`Comment Text`, event.data.text.length > 1024 ? `${event.data.text.trim().slice(0, 1020)}...` : event.data.text) .setTimestamp(event.data.dateLastEdited) send(addDiscordUserData(embed, event.memberCreator)) } else { if (!eventEnabled(`commentAdded`)) return embed .setTitle(`Comment added to card!`) .setDescription(`**CARD:** ${event.data.card.name} — **[CARD LINK](https://trello.com/c/${event.data.card.shortLink})**\n\n**EVENT:** Card comment added (see below for comment text) by **[${conf.realNames ? event.memberCreator.fullName : event.memberCreator.username}](https://trello.com/${event.memberCreator.username})**`) .addField(`Comment Text`, event.data.text.length > 1024 ? `${event.data.text.trim().slice(0, 1020)}...` : event.data.text) send(addDiscordUserData(embed, event.memberCreator)) } })
function getTrackEmbed(msg, spotifyId, withPreview) { spotifyApi.getTrack(spotifyId) .then(data => { const apiResponse = data.body; let artists = apiResponse.artists.map(artist => artist.name); const embed = new RichEmbed() .setColor([30, 215, 96]) .setThumbnail(apiResponse.album.images[0].url) .setAuthor('Click to listen on Spotify', 'https://image.flaticon.com/icons/png/512/174/174872.png', apiResponse.external_urls.spotify) .addField('Artist', artists.join(', '), true) .addField('Title', apiResponse.name, true) .addField('Length', calculateDuration(apiResponse.duration_ms), true) .addField('Album', apiResponse.album.name, true) .addField('Parental Advisory', ((apiResponse.explicit) ? 'contains explicit lyrics' : 'none applicable'), true) .addField('Availability', `Available in ${apiResponse.available_markets.length} countrys`, true) .addField('Popularity', `${apiResponse.popularity}%`, true); msg.edit({ embed }); if (withPreview) msg.channel.send(`Got spotify? Click below to play! ${apiResponse.external_urls.spotify}`); }).catch(err => { throw `Something went wrong! ${err}`; }); }
async run(message, args, level, settings, texts) { const query = args.join(" "); if (!query) return message.channel.send("You must provide a term to search for."); fetch(`http://api.urbandictionary.com/v0/define?term=${query}`) .then(res => res.json()) .then(json => { const data = json.list[0]; const definition = data.definition.replace(/[[\]]+/g, ""); const example = data.example.replace(/[[\]]+/g, ""); const embed = new RichEmbed() .setColor(50687) .setAuthor("Urban Dictionary", "https://vgy.me/ScvJzi.jpg") .setDescription(`Displaying Urban Dictionary definition for "**${data.word}**"\n<${data.permalink}>`) .addField("» Definition", `**${definition.substring(0, 1000)}...**`) .addField("» Example", `${example.substring(0, 1000)}...`) .setFooter(`Definition 1 of ${json.list.length}`) .setTimestamp(); return message.channel.send({ embed }); }) .catch(error => { this.client.logger.error(error); return message.channel.send(texts.general.error.replace(/{{err}}/g, error.message)); }); }
function sendCommands(channel) { const prefix = config.prefixes[(channel.guild || channel).id] || "/"; const rich = new Discord.RichEmbed(); rich.setTitle("Reposter Commands"); rich.setDescription("By MysteryPancake"); rich.setFooter(client.user.id, client.user.displayAvatarURL); rich.setAuthor(niceName(channel, channel, client.user), client.user.displayAvatarURL, "https://github.com/MysteryPancake/Discord-Reposter"); rich.setThumbnail(client.user.displayAvatarURL); rich.setTimestamp(); rich.setURL("https://github.com/MysteryPancake/Discord-Reposter#commands"); rich.addField("Repost To", "*Reposts to a channel.*```" + prefix + "repost <CHANNEL>\n" + prefix + "repost to <CHANNEL>```", false); rich.addField("Repost From", "*Reposts from a channel.*```" + prefix + "repost from <CHANNEL>```", false); rich.addField("Repost Webhook", "*Reposts through a webhook.*```" + prefix + "reposthook\n" + prefix + "repostwebhook```Instead of:```" + prefix + "repost```", false); rich.addField("Repost Live", "*Reposts messages as they come.*```" + prefix + "repostlive\n" + prefix + "repostlivehook```Instead of:```" + prefix + "repost```", false); rich.addField("Repost Stop", "*Stops reposting.*```" + prefix + "repost stop\n" + prefix + "repost halt\n" + prefix + "repost cease\n" + prefix + "repost terminate\n" + prefix + "repost suspend\n" + prefix + "repost cancel\n" + prefix + "repost die\n" + prefix + "repost end```", false); rich.addField("Repost Commands", "*Posts the command list.*```" + prefix + "repost help\n" + prefix + "repost commands```", false); rich.addField("Repost Replace", "*Replaces text when reposting.*```" + prefix + "repost replace <FIND> <REPLACE>```", false); rich.addField("Repost Replacements", "*Posts the replacement list.*```" + prefix + "repost replacements```", false); rich.addField("Repost Prefix", "*Changes the bot prefix.*```" + prefix + "repost prefix <PREFIX>```", false); rich.addField("Repost Tags", "*Toggles user tags when reposting.*```" + prefix + "repost tags\n" + prefix + "repost tags <STATE>```", false); rich.addField("Repost Nicknames", "*Toggles nicknames when reposting.*```" + prefix + "repost nicknames\n" + prefix + "repost nicknames <STATE>```", false); rich.addField("Repost Pins", "*Toggles pins when reposting.*```" + prefix + "repost pins\n" + prefix + "repost pins <STATE>```", false); rich.addField("Channel ID", "```" + channel.id + "```", false); channel.send(rich).catch(console.error); }
async run(message, args, level) { const chan = message.channel; let topic; if (chan.topic && chan.topic.length > 2048) topic = "[Too long to display!]"; else topic = chan.topic; const createdTimestamp = moment.utc(chan.createdAt).format("YYYYMMDD"); const randomColor = "#0000".replace(/0/g, () => { return (~~(Math.random() * 16)).toString(16); }); const embed = new RichEmbed() .setColor(randomColor) .setThumbnail("https://vgy.me/9fSC7k.png") .setTitle(`Channel Information for #${chan.name}`) .addField("Created", chan.createdAt, true) .addField("Age", moment(createdTimestamp, "YYYYMMDD").fromNow().slice(0, -4), true) .addField("Type", chan.type.toProperCase(), true) .addField("Position", chan.calculatedPosition, true) .addField("Parent", !chan.parent ? "None" : chan.parent.name, true) .addField("NSFW", chan.nsfw.toString().toProperCase(), true) .addField("Deletable", chan.deletable.toString().toProperCase(), true) .addField("Topic", !topic ? "No topic set." : topic, true) .setFooter(`Channel ID: ${chan.id}`, "https://vgy.me/167efD.png") .setTimestamp(); message.channel.send({ embed }); }
function richEmbed(embed, channel) { const rich = new Discord.RichEmbed(); if (embed.author) { rich.setAuthor(replaceAll(channel, embed.author.name), embed.author.iconURL, embed.author.url); } rich.setColor(embed.color); if (embed.description) { rich.setDescription(replaceAll(channel, embed.description)); } for (let i = 0; i < embed.fields.length; i++) { const field = embed.fields[i]; rich.addField(replaceAll(channel, field.name), replaceAll(channel, field.value), field.inline); } if (embed.footer) { rich.setFooter(replaceAll(channel, embed.footer.text), embed.footer.iconURL); } if (embed.image) { rich.setImage(embed.image.url); } if (embed.thumbnail) { rich.setThumbnail(embed.thumbnail.url); } rich.setTimestamp(embed.timestamp); if (embed.title) { rich.setTitle(replaceAll(channel, embed.title)); } rich.setURL(embed.url); return rich; }
function getPlaylistEmbed(msg, user, spotifyId, withPreview) { spotifyApi.getPlaylist(user, spotifyId) .then(data => { const apiResponse = data.body; const embed = new RichEmbed() .setColor([30, 215, 96]) .setThumbnail(apiResponse.images[0].url) .setAuthor('Click to listen on Spotify', 'https://image.flaticon.com/icons/png/512/174/174872.png', apiResponse.external_urls.spotify) .addField('Playlist Name', apiResponse.name, true) .addField('Created by', apiResponse.owner.display_name, true) .addField('Description', apiResponse.description, true) .addField('Public Playlist', ((apiResponse.public) ? 'Yes' : 'No'), true) .addField('Collaborative', ((apiResponse.collaborative) ? 'Yes' : 'No'), true) .addField('Followers', apiResponse.followers.total, true) .addField('Track Count', apiResponse.tracks.total, true); msg.edit({ embed }); if (withPreview) msg.channel.send(`Got spotify? Click below to play! ${apiResponse.external_urls.spotify}`); }).catch(err => { throw `Something went wrong! ${err}`; }); }
Sours: https://www.tabnine.com/code/javascript/functions/discord.js/RichEmbed/addField
  1. Heroku logs command
  2. Cabins rainbow springs state park
  3. 1990 oldsmobile for sale
  4. Diy cabinet legs
  5. Sonos move pair

# Embeds

If you have been around on Discord for a bit, chances are you have seen these special messages, often sent by bots. They can have a colored border, embedded images, text fields, and other fancy properties.

In the following section, we will explain how to compose an embed, send it, and what you need to be aware of while doing so.

# Embed preview

Here is an example of how an embed may look. We will go over embed construction in the next part of this guide.

Guide Bot Bot 10/12/2021

Some title

Some description here

Regular field title

Some value here

Inline field title

Some value here

Inline field title

Some value here

Inline field title

Some value here

# Using the embed constructor

discord.js features the open in new window utility class for easy construction and manipulation of embeds.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

TIP

You don't need to include all the elements showcased above. If you want a simpler embed, leave some out.

The method accepts a open in new window, e.g. an integer, HEX color string, an array of RGB values or specific color strings.

To add a blank field to the embed, you can use .

The above example chains the manipulating methods to the newly created MessageEmbed object. If you want to modify the embed based on conditions, you will need to reference it as the constant (for our example).

1
2
3
4
5

# Using an embed object

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

TIP

You don't need to include all the elements showcased above. If you want a simpler embed, leave some out.

If you want to modify the embed object based on conditions, you will need to reference it directly (as for our example). You can then (re)assign the property values as you would with any other object.

1
2
3
4
5

# Attaching images

You can upload images with your embedded message and use them as source for embed fields that support image URLs by constructing a open in new window from them to send as message option alongside the embed. The attachment parameter takes a BufferResolvable or Stream including the URL to an external image.

You can then reference and use the images inside the embed itself with .

TIP

If you plan to attach the same image repeatedly, consider hosting it online and providing the URL in the respective embed field instead. This also makes your bot respond faster since it doesn't need to upload the image with every response depending on it.

# Using the MessageEmbed builder

1
2
3
4
5
6
7
8

# Using an embed object

1
2
3
4
5
6
7
8
9
10
11
12

WARNING

If the images don't display inside the embed but outside of it, double-check your syntax to make sure it's as shown above.

# Resending and editing

We will now explain how to edit embedded message content and resend a received embed.

# Resending a received embed

To forward a received embed you retrieve it from the messages embed array () and pass it to the MessageEmbed can then be edited before sending it again.

WARNING

We deliberately create a new Embed here instead of just modifying directly to keep the cache valid. If we were not to do this, the embed in cache on the original message would diverge from what the actual embed looks like, which can result in unexpected behavior down the line!

1
2
3
4

# Editing the embedded message content

To edit the content of an embed you need to pass a new MessageEmbed structure or embed object to the messages method.

1
2
3
4
5

If you want to build the new embed data on a previously sent embed template, make sure to read the caveats in the previous section.

# Notes

  • To display fields side-by-side, you need at least two consecutive fields set to
  • The timestamp will automatically adjust the timezone depending on the user's device
  • Mentions of any kind will only render correctly in titles, descriptions, and field values
  • Mentions in embeds will not trigger a notification
  • Embeds allow masked links (e.g. ), but only in description and field values

# Embed limits

There are a few limits to be aware of while planning your embeds due to the API's limitations. Here is a quick reference you can come back to:

  • Embed titles are limited to 256 characters
  • Embed descriptions are limited to 4096 characters
  • There can be up to 25 fields
  • A field's name is limited to 256 characters and its value to 1024 characters
  • The footer text is limited to 2048 characters
  • The author name is limited to 256 characters
  • The sum of all characters from all embed structures in a message must not exceed 6000 characters
  • Ten embeds can be sent per message

Source: Discord API documentationopen in new window

Edit this page open in new window

Last Updated: 9/29/2021, 3:04:03 AM

Sours: https://discordjs.guide/popular-topics/embeds.html
Discord Custom Embeds - Make Your Server Beautiful - 2020

.

Discord rich embed

.

How to Make EMBEDDED Info Channels on Discord [Embed Rules Message!]

.

You will also be interested:

.



846 847 848 849 850