BetterEmbed & Embed Templates

BetterEmbed is a class from the discord.js-better-embed library that I've made, you can see the code here.

Documentation

This is a class for creating an Embed Object, but a bit simpler like this :

// MessageEmbed:
const {MessageEmbed} = require('discord.js');
const embed = new MessageEmbed();
embed.setImage('url');
embed.setAuthor('name', 'icon_url');
embed.setTimestamp();
embed.setFooter(client.user.username, client.user.displayAvatarURL());

// Cutting the text if too long:
embed.setDescription(embed.description.slice(0, 2048));

// BetterEmbed:
const {BetterEmbed} = require('advanced-command-handler');
const embed = BetterEmbed.fromTemplate('basic', {
    client,
});
embed.setImage('url');
embed.setAuthor('name', 'icon_url');

embed.cutIfTooLong();

Using templates

Templates are a good way of automating and simplifying your code. You can use them like this:

const {BetterEmbed, templates} = require('advanced-command-handler');
templates.funny = {
    title: '${client.user.username} says that you are funny !',
    ...templates.color, // Adding the default 'color' template
};

const embed = BetterEmbed.fromTemplate('funny', {client: message.client});
message.channel.send(embed);

This can simplify your embeds declarations and let you have more automation. Like if you use the color templates in your templates, if you change the template, every embed will have a different color without changing anything to them! So feel free to add as many templates as you need.

Default templates

const templates = {
    basic: {
        footer: {
            text: '${client.user.username}',
            iconURL: '${client.user.displayAvatarURL()}',
        },
        timestamp: new Date(),
    },
    color: {
        color: '#4b5afd',
    },
    get complete() {
        return {
            ...this.basic, // includes the 'basic' template
            ...this.color, // includes the 'color' template
            title: '${title}',
            description: '${description}',
        };
    },
    get image() {
        return {
            ...this.complete, // includes the 'complete' template
            image: {
                url: '${image}',
            },
        };
    },
}

You can overwrite default templates but these are used in the advanced-command-handler module so it could break things if you change them completely.

You can for example change the color property of the color template without any issue.

Last updated