Enhanced Embed Builder
Learn how to create beautiful embeds using meowcord's enhanced Embed class with chainable methods.
Introduction
Meowcord v0.1.6 introduces an enhanced Embed class that extends Discord.js's EmbedBuilder with chainable methods and additional features like hex color support. This makes creating rich embeds much more intuitive and readable.
Basic Usage
Import the Embed class and create beautiful embeds with chainable methods:
const { Meow, Intents, Embed } = require("meowcord");
const bot = new Meow({
intents: [Intents.Guilds, Intents.GuildMessages, Intents.MessageContent],
prefix: "!",
});
bot.basicCommand({
cmdName: "embed",
cmdCode: async (message) => {
const embed = new Embed()
.title("Hello World!")
.description("This is a beautiful embed created with meowcord")
.color("#FF69B4")
.timestamp();
message.reply({ embeds: [embed] });
}
});
Available Methods
The enhanced Embed class provides the following chainable methods:
const embed = new Embed()
.title("Embed Title") // Set the title
.description("Embed description") // Set the description
.color("#FF69B4") // Set color (hex or number)
.footer("Footer text", "icon_url") // Set footer with optional icon
.timestamp(true) // Add current timestamp
.image("https://example.com/image.png") // Set main image
.thumbnail("https://example.com/thumb.png") // Set thumbnail
.author("Author Name", "icon_url", "url") // Set author with optional icon and URL
.url("https://example.com") // Set embed URL
.addField("Field Name", "Field Value", true); // Add a field (inline optional)
Hex Color Support
The enhanced Embed class automatically parses hex color strings:
// All of these work:
const embed1 = new Embed().color("#FF69B4"); // Hex string
const embed2 = new Embed().color("#ff69b4"); // Lowercase hex
const embed3 = new Embed().color(0xFF69B4); // Hex number
const embed4 = new Embed().color(16738484); // Decimal number
// Popular colors
const redEmbed = new Embed().color("#FF0000");
const blueEmbed = new Embed().color("#0000FF");
const greenEmbed = new Embed().color("#00FF00");
const pinkEmbed = new Embed().color("#FF69B4");
Complete Embed Example
Here's an example of a fully-featured embed:
bot.basicCommand({
cmdName: "userinfo",
cmdCode: async (message) => {
const user = message.mentions.users.first() || message.author;
const member = message.guild.members.cache.get(user.id);
const embed = new Embed()
.title(`User Information: ${user.tag}`)
.description(`Detailed information about ${user.username}`)
.color("#FF69B4")
.thumbnail(user.displayAvatarURL({ dynamic: true }))
.author(
user.tag,
user.displayAvatarURL({ dynamic: true }),
`https://discord.com/users/${user.id}`
)
.addField("User ID", user.id, true)
.addField("Username", user.username, true)
.addField("Discriminator", user.discriminator, true)
.addField("Account Created", user.createdAt.toDateString(), true)
.addField("Joined Server", member?.joinedAt?.toDateString() || "Unknown", true)
.addField("Bot Account", user.bot ? "Yes" : "No", true)
.footer("Requested by " + message.author.tag, message.author.displayAvatarURL())
.timestamp();
message.reply({ embeds: [embed] });
}
});
Using with Slash Commands
The enhanced Embed class works perfectly with interaction commands:
bot.interactionCommand({
cmdName: "serverinfo",
interactionType: "slash",
cmdCode: async (interaction) => {
const guild = interaction.guild;
const embed = new Embed()
.title(guild.name)
.description("Server Information")
.color("#FF69B4")
.thumbnail(guild.iconURL({ dynamic: true }))
.addField("Owner", `<@${guild.ownerId}>`, true)
.addField("Members", guild.memberCount.toString(), true)
.addField("Created", guild.createdAt.toDateString(), true)
.addField("Channels", guild.channels.cache.size.toString(), true)
.addField("Roles", guild.roles.cache.size.toString(), true)
.addField("Emojis", guild.emojis.cache.size.toString(), true)
.footer(`Server ID: ${guild.id}`)
.timestamp();
await interaction.reply({ embeds: [embed] });
}
});
Multiple Embeds
You can send multiple embeds in a single message:
bot.basicCommand({
cmdName: "multiembed",
cmdCode: async (message) => {
const embed1 = new Embed()
.title("First Embed")
.description("This is the first embed")
.color("#FF0000");
const embed2 = new Embed()
.title("Second Embed")
.description("This is the second embed")
.color("#00FF00");
const embed3 = new Embed()
.title("Third Embed")
.description("This is the third embed")
.color("#0000FF");
message.reply({ embeds: [embed1, embed2, embed3] });
}
});
Error Handling
Always handle potential errors when working with embeds:
bot.basicCommand({
cmdName: "safeembed",
cmdCode: async (message) => {
try {
const embed = new Embed()
.title("Safe Embed")
.description("This embed has error handling")
.color("#FF69B4")
.timestamp();
await message.reply({ embeds: [embed] });
} catch (error) {
console.error("Error creating embed:", error);
message.reply("Sorry, there was an error creating the embed.");
}
}
});
Embed Limits
Keep in mind Discord's embed limits:
- Title: 256 characters
- Description: 4096 characters
- Fields: 25 fields maximum
- Field name: 256 characters
- Field value: 1024 characters
- Footer text: 2048 characters
- Author name: 256 characters
- Total characters: 6000 characters across all fields