I was trying to do make welcome message when someone gets on my server but I am trying to do so it takes embed from another file. It says guildMember is not defined and I understand that but I don’t know how to define it.
Here is my index.js:
const express = require('express');
const app = express();
const port = 8080;
app.get('/', (req, res) => res.send('Hello World!'));
app.listen(port, () => console.log('Hosted site'));
const { Client, Intents } = require('discord.js');
const Discord = require('discord.js');
const variable = require('./commands/variable');
const welcome = require('./commands/welcome');
const mongoose = require('mongoose');
mongoose.connect(process.env['mongo'], { useNewUrlParser: true, useUnifiedTopology: true }).then(console.log('Mongo is connected!'))
const fs = require('fs');
const prefix = ('m?');
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS],
partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
});
client.commands = new Discord.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)
}
client.once('ready', async () => {
console.log('MBot is ready!');
client.user.setActivity("Vedad", {
type: "LISTENING"
});
});
client.on('guildMemberAdd', guildMember => {
guildMember.guild.channels.cache.get('975033510186324069').send(welcome.wlc)
})
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 === 'wlcmsgid') {
client.commands.get('wlcmsgid').execute(message, args, Discord, client);}
else if (command === 'ping') {
client.commands.get('ping').execute(message, args, Discord, client);}
})
client.login(process.env['token']);
here is welcome.js file:
const Discord = require('discord.js');
const variable = require('./variable');
module.exports.wlc = new Discord.MessageEmbed()
.setColor('#000000')
.setDescription(`━━━━━━━━━━━━━━━━━━━━━━━━
Welcome <@${guildMember.user.id}> to **GhostCommunity!**
━━━━━━━━━━━━━━━━━━━━━━━━`)
Here is my console error:
ReferenceError: guildMember is not defined
at Object.<anonymous> (/home/runner/MBot-1/commands/welcome.js:8:21)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/home/runner/MBot-1/index.js:10:17)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
I just can’t figure out how to define guildMember in welcome.js. Please help, thank’s