I want to ask how to access a guildMember via an event handler.
Here is how I'm supposed to write it (and so many others have done this too)...
client.on('guildMemberAdd', guildMember => {
let welcomeRole = guildMember.guild.roles.cache.find(role => role.name === 'Member');
guildMember.roles.add(welcomeRole);
guildMember.guild.channels.cache.get('TheChannelID').send(`Welcome, <@${guildMember.user.id}>, to our server! ... Check out the rules-cmd channel!`);
});
...but I have an event handler, shown below...
//My event handler
const fs = require('fs');
module.exports = (client, Discord) =>{
const load_dir = (dirs) =>{
const event_files = fs.readdirSync(`./events/${dirs}`).filter(file => file.endsWith('.js'));
for (const file of event_files) {
const event = require(`../events/${dirs}/${file}`);
const event_name = file.split('.')[0];
client.on(event_name, event.bind(null, Discord, client));
}
}
['client', 'guild'].forEach(e => load_dir(e));
}
and here is my ATTEMPT at trying to recreate this in a separate guildMemberAdd.js file, but nothing seems to be working...
module.exports = (Discord, client, message) =>{
const guildMember = Discord.GuildMember;
let welcomeRole = guildMember.guild.roles.cache.find(role => role.name === 'Member');
guildMember.roles.add(welcomeRole);
guildMember.guild.channels.cache.get('TheChannelID').send(`Welcome, <@${guildMember.user.id}>, to our server! ... Check out the rules-cmd channel!`);
}
I have scrunched up my head for hours pondering the problem, can anybody help please?
Oh, and I got most of my code from CodeLyon. He taught it to us this way...
client.on('guildMemberAdd', guildMember => {
let welcomeRole = guildMember.guild.roles.cache.find(role => role.name === 'Member');
guildMember.roles.add(welcomeRole);
guildMember.guild.channels.cache.get('TheChannelID').send(`Welcome, <@${guildMember.user.id}>, to our server! ... Check out the rules-cmd channel!`);
});
...but he didn't tell us how to do it when he made his event handler. I fixed the member counter problem that people were asking in the comments, but I can't seem to fix this problem.
Here's CodeLyon's tutorials...
https://www.youtube.com/playlist?list=PLbbLC0BLaGjpyzN1rg-gK4dUqbn8eJQq4
PLEASE it will be of great appreciation if someone could help!
question from:
https://stackoverflow.com/questions/65950673/access-guildmember-via-event-handler