So i was recently trying to add a MessageEmbed for my discord bot, but i get this error:
TypeError: Discord.MessageEmbed is not a constructor
I was wondering if anyone knows how to fix this, i have tried some of the rips i could find online, some include trying to re-install node.js and discord.js, other mention a different method like using NewMessageEmbed() instead, but none of them have been working for me, it would be great someone with a bit more experience than me could provide a solution, i have provided all the code involved and screenshot of the error, thanks in advance :)
Command file:
module.exports = {
name: 'command',
description: "Embeds!",
execute(message, args, Discord){
const newEmbed = new Discord.MessageEmbed()
.setColor('#FFA62B')
.setTitle('Rules')
.setURL('https://discord.gg/fPAsvEey2k')
.setDescription('**This is an embed for the server rules.**')
.addFields(
{name: '1.', value: 'Treat everyone with respect. Absolutely no harassment, witch hunting, sexism, racism or hate speech will be tolerated.'},
{name: '2.', value: 'No spam or self-promotion (server invites, advertisements, etc) without permission from a staff member. This includes DMing fellow members.'},
{name: '3.', value: 'No NSFW or obscene content. This includes text, images or links featuring nudity, sex, hard violence or other graphically disturbing content.'},
{name: '4.', value: 'if you see something against the rules or something that makes you feel unsafe, let staff know. We want this server to be a welcoming space!'},
{name: '5.', value: 'Keep public conversations in english.'},
{name: '6.', value: 'This list is not exhaustive and will be updated as we see fit.'}
)
.setImage('./images/rules.png')
.setFooter('Make sure to follow the rules');
message.channel.send(newEmbed);
}
}
Main file:
// grabs the discord.js bot file for import //
const {Client, Intents, Collection} = require('discord.js');
// create the client for the bot //
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
// prefix to use for bot commands //
const prefix = '!';
const fs = require('fs');
const Discord = require('./commands/discord');
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
// log to console that the bot has succesfully logged in //
client.once('ready', () => {
console.log("Reformed Esports is online");
});
/* Command handler, checking if message starts with prefix and is not the bot,
allowing commands to have multiple words */
client.on('message', message =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ /);
const command = args.shift().toLowerCase();
if(command === 'ping'){
client.commands.get('ping').execute(message, args);
} else if(command === 'discord'){
client.commands.get('discord').execute(message, args);
} else if(command === 'pugs') {
client.commands.get('pugs').execute(message, args);
} else if(command === 'command'){
client.commands.get('command').execute(message, args, Discord)
}
});
// bot login using discord bot token //
client.login('blank');
CodePudding user response:
You should be passing the discord.js module but instead you pass a file. This may have different functions, properties, etc than the discord.js module.
This code will fix the error:
client.commands.get('command').execute(message, args, require('discord.js'))
Additionally, embeds must now be sent using the embeds
property
message.channel.send({ embeds: [newEmbed] })
CodePudding user response:
It looks like you are sending ./commands/discord
as an argument instead of the real discord.js package. I would add Embed
to the const {Client, Intents, Collection} = require('discord.js');
, and send Embed
instead of Discord
inside of client.commands.get('command').execute(message, args, Discord)
.