简体   繁体   中英

How to add embeds in Discord V12

I'm new to javascript and programming. I'm trying to add embeds to my commands but I'm struggling quite badly. This is what my code looks like:

client.on('message', async (message) => {

        if (message.content.toLowerCase() === '?help') {
          const embed = new Discord.MessageEmbed()
            .setTitle('This is a test Embed.')
            .setURL('https://example.com')
            .setAuthor('example')
            .setDescription('This is a test Description which we will see.')
            .setColor('#FF2D00')
            .setThumbnail('https://example.png')
            .setImage('https://example.png')
            .setFooter('This is a example footer', 'https://example.png')
            .addFields({
              name: 'Test Number 1',
              value: 'This is a example value',
              inline: true
            }, {
              name: 'Test Number 2',
              value: 'This is a example value',
              inline: true
            }, {
              name: 'Test Number 3',
              value: 'This is a example value'
            }, {
              name: 'Test Number 4',
              value: 'This is a example value'
            })
            .setTimestamp();

          message.channel.send(embed);
        }

And basically I keep getting an error from my console saying that: MessageEmbed is undefined and I don't know why.

(I'm really new to programming so sorry if this question is a bot question.)

Make sure you have the library imported:

const Discord = require("discord.js");

Or do it like so:

const { Client, CategoryChannel, MessageEmbed } = require("discord.js")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM