Attempting to create a simple welcome message embed. Here is my main.js
file without the login token:
const Discord = require('discord.js');
const client = new Discord.Client();
const MessageEmbed = new Discord.MessageEmbed();
const prefix = 'm.';
const fs = require('fs');
client.commands = new Discord.Collection();
client.events = new Discord.Collection();
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
and here is welcome.js
with the exception of defining channelId
:
module.exports = {
name: 'guildMemberAdd',
execute(member, Discord) {
console.log('login');
const message = `Welcome <@${member.id}> !`;
const channel = member.guild.channels.cache.get(channelId);
const joinEmbed = new Discord.MessageEmbed()
.setTitle(`New member!`)
.setDescription(message)
.setColor("#fab9c7");
channel.send({ joinEmbed });
},
};
The following error message occurred:
const joinEmbed = new Discord.MessageEmbed()
^
TypeError: Cannot read property 'MessageEmbed' of undefined
at Object.execute (C:\Users\Al\Desktop\MaikaBot\events\welcome.js:11:39)
at Client.<anonymous> (C:\Users\Al\Desktop\MaikaBot\main.js:17:44)
at Client.emit (events.js:400:28)
at Object.module.exports [as GUILD_MEMBER_ADD] (C:\Users\Al\Desktop\MaikaBot\node_modules\discord.js\src\client\websocket\handlers\GUILD_MEMBER_ADD.js:16:14)
at WebSocketManager.handlePacket (C:\Users\Al\Desktop\MaikaBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\Al\Desktop\MaikaBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\Al\Desktop\MaikaBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\Al\Desktop\MaikaBot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:400:28)
at Receiver.receiverOnMessage (C:\Users\Al\Desktop\MaikaBot\node_modules\ws\lib\websocket.js:970:20)
If this seems too basic, apologies as I'm still in the process of learning JavaScript. The module syntax continues to elude me.