RevolverSnake412
RevolverSnake412

Reputation: 103

Cannot read property 'MessageEmbed' of undefined

Created a discord bot that bans members I prefer responding with a message embed after banning someone but all I can do is a normal message I don't know why I can't create an embed even if I have discord.js up to date (v12)

I get the error:

C:\Users\oussa\OneDrive\Bureau\Discord Bot\index.js:45
  const BanEmbed = new Discord.MessageEmbed()
                               ^

TypeError: Cannot read property 'MessageEmbed' of undefined

Here is my code:

const { Client, Attachment, Message, Discord } = require("discord.js");
const { prefix, token } = require("./config.json");
const bot = new Client();

const ytdl = require("ytdl-core");
const request = require("request");
const cheerio = require("cheerio");

const queue = new Map();

bot.on("ready", () => {
    console.log("Client is online!");
    bot.user.setActivity("osu!");
    bot.user.setUsername("RevolverSnake412");
});

bot.on("message", (msg) => {
    const BanEmbed = new Discord.MessageEmbed()
        .setColor("#5300A6")
        .setTitle("title")
        .setAuthor("author")
        .setDescription("description")
        .setThumbnail("https://image.freepik.com/free-icon/sail-boat_318-1522.jpg")
        .setImage("https://img.ifunny.co/images/01b86faa3cedc450bffac646492c3a8717d30f74f41434761d45c66b9545d8c6_1.jpg")
        .setFooter("footer");

    switch (args[1]) {
        case "ban":
            const user = msg.mentions.users.first();

            if (user) {
                const member = msg.guild.member(user);

                if (member) {
                    member.ban({ ression: "..." }).then(() => {
                        msg.channel.send(BanEmbed);
                    });
                } else {
                    msg.channel.send("...");
                }
            } else {
                msg.channel.send("...");
            }

            break;
    }
});

bot.login(token);

Upvotes: 3

Views: 3656

Answers (1)

battlesqui_d
battlesqui_d

Reputation: 76

The error is in your destructuring assignment. Discord is not a property on discord.js, hence why it is undefined. You most likely want:

const { Client, Attachment, Message, MessageEmbed } = require("discord.js");

And then implement it like so

const BanEmbed = new MessageEmbed()

Side note, Attachment is not a valid property of discord.js either so you most likely want to change that to MessageAttachment.

API Docs: https://discord.js.org/#/docs/main/stable/class/MessageAttachment

Upvotes: 2

Related Questions