Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
guildMemberAdd event handler issues

This will be my third question of the day because I am obviously not smart with this. I am using discord.js v12 and my issue this time is with an event handler. The event handler has worked fine so far with things so far like the message or ready. I am right now trying to get a guildMemberAdd event that gives a new person that joins a role and then sends a message in the logs chat indicating they joined. When a user joins, the bot crashes. The guildMemberAdd works on my main index.js file, but won't work under the event handler.

crash log: https://imgur.com/a/MrMi536

here are a few pieces of code if they are needed.

Event Handler:

const { readdirSync } = require('fs');

module.exports = (client) => {
    const load = dirs => {
        const events = readdirSync(`./events/${dirs}/`).filter(d => d.endsWith('.js'));
        
        for(let file of events){
            const event = require(`../events/${dirs}/${file}`);
            let eventName = file.split('.')[0];
            client.on(eventName, event.bind(null, client));
        }
    }
    ['client', 'guild'].forEach(x => load(x));
}

guildMemberAdd:

module.exports = (Discord, client, guildMember) => {
    console.log(guildMember);
    
    guildMember.roles.add(guildMember.guild.roles.cache.find(role => role.name === "Member"));
    guildMember.channels.cache.get('767090422626779149').send('test');
}

index.js

// heads up that I'm using discord.js v12.4.1 because v13.1.0 is weird and I don't understand it lol

const fs = require('fs');
const Discord = require('discord.js');
require('dotenv').config();

const client = new Discord.Client(); // client = name of  bot

// client.on('guildMemberAdd', (guildMember) => {
   // guildMember.roles.add(guildMember.guild.roles.cache.find(role => role.name === "Member"));
// });

['aliases', 'commands'].forEach(x => client[x] = new Discord.Collection());
['command', 'event'].forEach(x => require(`./handlers/${x}`)(client));

client.login(process.env.CLIENT_TOKEN); // SECRET TOKEN

I haven't used discord.js or JavaScript in at least a year so any help is appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There seems to be a problem passing the guildMember object.

Maybe changing this can help you:

client.on(eventName, event.bind(null, client)); //change this

client.on(eventName, (...args) => event.bind(null, client, ...args)) //to this

Note: I am also not 100% sure if you can use guildMember or if you have to use member.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!