Embed
The Embed class is a thin wrapper around discord.js's EmbedBuilder that lets you build an embed from a single plain object instead of chaining setter calls. It's especially handy when the embed's content comes from JSON, a config file, or a database.
Creating an embed
const { Embed } = require("syntx.js");
const embed = new Embed();
embed.set({
title: "Welcome!",
description: "Thanks for joining the server.",
color: "Blue",
});Note
color accepts anything discord.js's EmbedBuilder#setColor() accepts: a named color like "Blue", a hex string like "#5865F2", or a number like 0x5865f2.
set(data, structureType)
Fills in the embed's fields from data. The second argument, structureType, controls which shape data is expected to have; 1 (the default) for simple flat fields, or 2 for a richer shape with linked title/author/footer objects, a fields array, and a timestamp.
Warning
structureType must be 1 or 2; anything else throws a SyntxError.
Structure type 1 (default)
| Field | Type | Description |
|---|---|---|
title | string | The embed title. |
description | string | The main text. |
color | ColorResolvable | The accent color of the embed. |
footer | string | Footer text. |
footerIcon | string (URL) | Small icon next to the footer. |
image | string (URL) | A large image at the bottom. |
thumbnail | string (URL) | A small image in the top-right. |
author | string | Author name, shown above the title. |
authorIcon | string (URL) | Small icon next to the author name. |
authorURL | string (URL) | Link applied to the author name. |
embed.set({
title: "Server rules",
description: "Please read before chatting.",
color: "#5865F2",
footer: "Updated today",
thumbnail: "https://example.com/icon.png",
});Structure type 2
title, author, and footer become objects so they can carry a link or icon, and you also get fields and timestamp.
| Field | Type | Description |
|---|---|---|
title | { content, url } | Title text plus an optional link. |
description | string | The main text. |
color | ColorResolvable | The accent color of the embed. |
image | string (URL) | A large image at the bottom. |
thumbnail | string (URL) | A small image in the top-right. |
author | { content, icon, url } | Author name, icon, and link. |
footer | { content, icon } | Footer text and icon. |
fields | { name, value, inline }[] | Embed fields. |
timestamp | boolean | Adds the current time when true. |
embed.set(
{
title: { content: "Patch notes", url: "https://example.com/changelog" },
description: "Here is what changed this week.",
color: "Green",
author: { content: "Bot Team", icon: "https://example.com/avatar.png" },
fields: [
{ name: "Fixed", value: "Crash on startup", inline: true },
{ name: "Added", value: "Slash command support", inline: true },
],
timestamp: true,
},
2,
);Tip
In structure type 2, title is always read as { content, url }. If you don't need a clickable title, structure type 1 is simpler; or just pass title: { content: "..." } and leave url out.
Methods
embed.addField(name, value, inline)
Adds a single field to the embed.
embed.addField("Members", "1,204", true);Warning
addField() only has an effect when the embed was built with structure type 1 (the default). If you called set() with structureType: 2, it silently does nothing instead of throwing; use the fields array inside set() for structure type 2 embeds.
embed.setURL(url)
Sets a link on the embed title.
embed.setURL("https://example.com");Warning
Like addField(), this only applies to structure type 1. For structure type 2, set title.url inside set() instead.
embed.timestamp()
Stamps the embed with the current time.
embed.timestamp();Note
Also structure-type-1-only. For structure type 2, pass timestamp: true inside set(). Either way, only the current time can be used; there's no way to set a custom date.
embed.build()
Returns the underlying discord.js EmbedBuilder, ready to send.
message.channel.send({ embeds: [embed.build()] });Full example
const { Embed } = require("syntx.js");
const embed = new Embed();
embed.set({
title: "Welcome to the server!",
description: "Make sure to read the rules.",
color: "Blue",
thumbnail: member.user.displayAvatarURL(),
});
embed.addField("Member count", `${member.guild.memberCount}`, true);
embed.timestamp();
channel.send({ embeds: [embed.build()] });