Home > Blockchain >  Embeds are not working (On every embed error: new Discord.MessageEmbed is not a constructor)
Embeds are not working (On every embed error: new Discord.MessageEmbed is not a constructor)

Time:05-21

I recently added a command handler into my discord bot. All the commands that had Embeds came up with the error "Discord.MessageEmbed is not a constructor".

code:

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

module.exports = {
    name: 'embed',
    description: "Embeds!",
    execute(client, message, args, Discord){
        const embed = new Discord.MessageEmbed()
        

        .setColor('#3498DB')
        .setAuthor("Afghar | Test", "https://i.imgur.com/jF4xyap.png")
        .addFields(
            { name: "Test", value: "- `test`", inline: true },
            { name: "Test", value: "- `test`", inline: true },
            { name: '‎', value: '‎' },

        )

        .addField("\u200b", "\u200b")
        .setTimestamp()
        .setFooter("test", "http://i.imgur.com/w1vhFSR.png");

        message.channel.send({ embeds: [embed] });
    }
}

full error:

C:\Asghar\commands\test.js:7
        const embed = new Discord.MessageEmbed()
                      ^

TypeError: Discord.MessageEmbed is not a constructor
    at Object.execute (C:\Asghar\commands\test.js:7:23)
    at module.exports (C:\Asghar\events\guild\message.js:11:25)
    at Client.emit (node:events:527:28)
    at MessageCreateAction.handle (C:\Asghar\node_modules\discord.js\src\client\actions\MessageCreate.js:34:18)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Asghar\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Asghar\node_modules\discord.js\src\client\websocket\WebSocketManager.js:351:31)
    at WebSocketShard.onPacket (C:\Asghar\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (C:\Asghar\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\Asghar\node_modules\ws\lib\event-target.js:199:18)
    at WebSocket.emit (node:events:527:28)

CodePudding user response:

npm uninstall -S discord.js

and then

npm i discord.js --save

CodePudding user response:

Discord.MessageEmbed assumes you imported the discord.js module as a variable named Discord. Your execute method seems to have a different Discord variable which is not the actual discord.js module:

    execute(client, message, args, Discord){

This overrides your original Discord variable which is the discord.js module:

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

You should see what that new Discord variable in the execute method does, and delete it if it isn't needed, or rename it.

  • Related