Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Latest commit

 

History

History
47 lines (39 loc) · 1.55 KB

using-a-richembed-in-a-command.md

File metadata and controls

47 lines (39 loc) · 1.55 KB

RichEmbeds/MessageEmbeds

You may have noticed that if you try to use a RichEmbed (or MessageEmbed for master) in your command, that there's no way to create the new embed, as new Discord.RichEmbed() is going to say Discord is undefined. That's because when using a RichEmbed, we need to require Discord.js alongside Commando.

const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');

Now that it has been required, our RichEmbed won't be undefined. Let's create a new command that embeds the content of the user's message.

const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');

module.exports = class EmbedCommand extends Command {
    constructor(client) {
        super(client, {
            name: 'embed',
            group: 'group2',
            memberName: 'embed',
            description: 'Embeds the text you provide.',
            examples: ['embed Embeds are cool.'],
            args: [
                {
                    key: 'text',
                    prompt: 'What text would you like the bot to embed?',
                    type: 'string'
                }
            ]
        });    
    }

    run(msg, args) {
        const { text } = args;
        const embed = new RichEmbed()
            .setDescription(text)
            .setAuthor(msg.author.username, msg.author.displayAvatarURL)
            .setColor(0x00AE86)
            .setTimestamp();
        return msg.embed(embed);
    }
};

Simple isn't it? It's just like regular Discord.js RichEmbeds.