So recently I tried adding a command handler into my discord bot. All the commands that had Embeds came up with the error "Discord.MessageEmbed is not a constructor".
this only happened when i added the command handler but the commands worked fine without it.
further details: discord.js version [12] node version [14.15.3]
code:
const { MessageEmbed } = require("discord.js");
module.exports = {
name: 'help',
description: "Sets up a dynamic help message!",
async execute(message, args, Discord, client) {
const purge = ':one:';
const music = ':two:';
const ban = ':three:';
const purgeembed = new MessageEmbed()
.setColor('RANDOM')
.setTitle('purge info')
.setDescription("this is a embed for more info about the purge command and how to use it")
.addFields(
{name: ' ', value: "`this command allows a user to purge (delete) messages that are less than 14 days old`", inline: true},
{name: ' ', value: '%purge [number of messages < 1000]'}
)
.setFooter("check bellow for how it works [unfinished]");
const musicembed = new Discord.MessageEmbed()
.setColor('RANDOM')
.setTitle('music info')
.setDescription("this is a embed for more info about the music command and how to use it")
.addFields(
{name: ' ', value: "`this command allows a user to listen to music in a voice channel with alot of options like playing music from a link or by searching for the song through yt there is also a Queuing for music`", inline: true},
{name: ' ', value: "`assoiciated commands:`",},
{name: ' ', value: "`......`", inline: true},
{name: ' ', value: "`......`", inline: true},
{name: ' ', value: "`......`", inline: true},
{name: ' ', value: "`......`", inline: true},
{name: ' ', value: "`......`", inline: true},
{name: ' ', value: "`%...`"},
)
.setFooter("check bellow for how it works [unfinished]");
const banembed = new Discord.MessageEmbed()
.setColor('RANDOM')
.setTitle('ban info')
.setDescription("this is a embed for more info about the ban command and how to use it")
.addFields(
{name: ' ', value: "`this command allows a moderator to ban a user`", inline: true},
{name: ' ', value: "`you can ban a user if you are a moderator but you need to give a reason to the owner first`"},
{name: ' ', value: "`%ban @user`"},
)
.setFooter("check bellow for how it works [unfinished]");
let embed = new Discord.MessageEmbed()
.setColor('RANDOM')
.setTitle('Choose a reaction for more info about a command!')
.setDescription('Choosing a reaction will allow you to get more info about a specific command!\n\n'
+ `${purge} for purge help\n\n`
+ `${music} for music help\n\n`
+ `${ban} for ban help\n\n`);
message.channel.send(embed).then(embedMessage => {
embedMessage.react('1️⃣');
embedMessage.react('2️⃣');
embedMessage.react('3️⃣');
});
message.client.on('messageReactionAdd', (reaction, user) => {
if (user.id === '795613081295650837'){
}else{
if (reaction.emoji.name === '1️⃣') {
message.channel.bulkDelete(1);
setTimeout(function(){
message.channel.send(purgeembed);
}, 600);
}
if (reaction.emoji.name === '2️⃣') {
message.channel.bulkDelete(1);
setTimeout(function(){
message.channel.send(musicembed);
}, 600);
}
if (reaction.emoji.name === '3️⃣') {
message.channel.bulkDelete(1);
setTimeout(function(){
message.channel.send(banembed);
}, 600);
}
else {
return;
}}
});
}
}
full error:
(node:15924) UnhandledPromiseRejectionWarning: TypeError: Discord.MessageEmbed is not a constructor
at Object.execute (C:\Users\x\Desktop\Advanced coding\discord bot\commands\help.js:25:28)
at module.exports (C:\Users\x\Desktop\Advanced coding\discord bot\events\guild\message.js:9:24)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Users\x\Desktop\Advanced coding\discord bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\x\Desktop\Advanced coding\discord bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\x\Desktop\Advanced coding\discord bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\x\Desktop\Advanced coding\discord bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\x\Desktop\Advanced coding\discord bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\x\Desktop\Advanced coding\discord bot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:315:20)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:15924) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:15924) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
C:\Users\x\Desktop\Advanced coding\discord bot\events\client\ready.js:9
Client.user.setPresence({
^
TypeError: Cannot read property 'setPresence' of undefined
at Timeout.presence [as _onTimeout] (C:\Users\x\Desktop\Advanced coding\discord bot\events\client\ready.js:9:27)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
main file:
const Discord = require('discord.js');
const client = new Discord.Client({partials: ["MESSAGE", "CHANNEL", "REACTION"]});
const fs = require('fs');
client.commands = new Discord.Collection();
client.events = new Discord.Collection();
['command_handler', 'event_handler'].forEach(handler =>{
require(`./handlers/${handler}`)(client, Discord);
})
/* 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);
}
client.once('ready', () => {
function presence() {
let status = ['<help for help'] //you can add how many you like
let rstatus = Math.floor(Math.random() * status.length); //this chooses a status from the ones you typed up
client.user.setPresence({
status: "online", //you can change to offline, dnd
type: "WATCHING",
activity: {
name: `${status[rstatus]}`, //rhese sets the status type: "WATCHING" //you can change to listening, streaming, playing (just a quick google search :) )
}
});
}
console.log(`Discord Bot ${client.user.tag} is online!`); // the presence needs to be like this, near the ready event
setInterval(presence, 30000) //you can reduce/add the time (milliseconds) if you reduce it l3ss then 15 seconds your bot will get ratelimited
});
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();
message.delete();
if(command === 'help'){
client.commands.get('help').execute(message, args, Discord);
}else if(command == 'purge'){
client.commands.get('purge').execute(message, args, Discord);
}else if(command == 'play'){
client.commands.get('play').execute(message, args, Discord);
}else if(command == 'congrat'){
client.commands.get('congrat').execute(message, args, Discord);
}else if(command == 'kick'){
client.commands.get('kick').execut(emessage, args, Discord);
}else if(command == 'ban'){
client.commands.get('ban').execute(message, args, Discord);
}else if(command == 'ping'){
client.commands.get('ping').execute(message, args, Discord);
}
}); */
client.login('token')
any help would be highly appreciated, thanks.