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

102
Views
Cannot understand how to use this handler

Hello this is my event handler

const fs = require('fs');

module.exports = (client, Discord) => {
  const load_dir = (dirs) => {
    const events_files = fs
      .readdirSync(`./events/${dirs}`)
      .filter((file) => file.endsWith('.js'));

    for (const file of events_files) {
      const event = require(`../events/${dirs}/${file}`);
      const event_name = file.split('.')[0];
      client.on(event_name, event.bind(null, client, Discord));
    }
  };

  ['client', 'guild'].forEach((e) => load_dir(e));
};

I have a ready event which works perfectly but when I added guildMemberAdd event it give me error ReferenceError: guildMember is not defined in line 5 this is my guildMemberAdd event

const GuildSettings = require('../../models/GuildSettings');

module.exports = async (client, messages, args, Discord) => {
  const guildSettings = await GuildSettings.findOne({
    guild_id: guildMember.guild.id,
  });
  if (!guildSettings) return;
  if (!guildSettings.welcome_channel_id) {
    return;
  }

  const welcomeChannel = guildSettings.welcome_channel_id;

  if (!guildMember.guild.channels.cache.has(welcomeChannel)) {
    return;
  }
  if (guildSettings.welcome_role_id) {
    if (!guildMember.guild.roles.cache.has(guildSettings.welcome_role_id)) {
      return;
    }
    guildMember.roles.add(guildSettings.welcome_role_id);
  }

  guildMember.guild.channels.cache
    .get(welcomeChannel)
    .send(`Welcome <@${guildMember.user.id}> to Our server`);
};
about 4 years ago · Juan Pablo Isaza
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!