#GuildMemberAdd

27 messages · Page 1 of 1 (latest)

iron shaleBOT
zinc forum
#

once again, say whats not working and provide error logs

fast willow
daring prairie
#

what do you mean “select”

#

also, the guildMemberAdd event doesn’t emit a “guild” parameter

#

you probably want to be using member.guild.id

fast willow
fast willow
# daring prairie ^

node:events:496
throw er; // Unhandled 'error' event
^

TypeError: Cannot read properties of undefined (reading 'id')

daring prairie
#

do you have the GuildMembers intent?

fast willow
#

Yes

daring prairie
#

please show that you do

fast willow
daring prairie
#

log member.guild

fast willow
#

undefined

daring prairie
#

okay, log member

#

that’s your Client

#

can you show your event handler? seems like you’re passing client as a parameter

#

which you really shouldn’t do

fast willow
#
const fs = require('node:fs');
const { Events } = require('discord.js');
const ReadFolder = require('./ReadFolder.js');

module.exports = function (client) {
    // Skip if the events folder was deleted
    if (!fs.existsSync(`${__dirname}/../events/`)) return;

    // This is a recursive function that will go through every folder and subfolder
    const files = ReadFolder('events');
    for (const { path, data } of files) {
        // This is more a sanity check than anything
        // It's just here to make sure everything loaded correctly
        if (typeof data.name !== 'string') {
            console.error(`Could not load ${path} : Missing name`);
            continue;
        }

        // We try to map the names to internal DJS events
        // This helps prevent silly mistakes like typos
        if (Events[data.name]) data.name = Events[data.name];

        // If a mapping wasn't successful then it's likely a custom event or a typo
        // It will still work if you use client.emit() but it will never fire on it's own
        if (!Events[data.name] && !Object.values(Events).includes(data.name)) {
            console.error(`Invalid event name "${data.name}" - Unknown to Discord.JS`);
        }
            
        // Again with the execute function lol
        if (typeof data.execute !== 'function') {
            console.error(`Could not load ${path} : Missing an execute function`);
            continue;
        }

        // This will add it to client.on() or client.once() respectively
        // The function.bind() forces client to be the first argument no matter what
        // It helps to prevent function nesting, also just easier to read in my opinion lol
        // client.on('...', (...args) => data.execute(client, ...args));
        // client.on('...', data.execute.bind(null, client));
        client[data.once ? 'once' : 'on'](data.name, data.execute.bind(null, client));
    }
    
    console.log(`Loaded ${files.length} events!`);
}

daring prairie
#

as i suspected

#

i suggest looking at the event handling from our guide

blazing stormBOT
#

guide Event Handling
Node.js uses an event-driven architecture, making it possible to execute code when a specific event occurs. The discord.js library takes full advantage of this. You can visit the Client documentation to see the full list of events. This page assumes you've followed the guide up to this point, and created your index.js and individual slash commands according to those pages. At this point, your index.js file has listeners for two events: ClientReady and InteractionCreate.

daring prairie
#

don’t pass client as a function parameter in the event handling client.on/once execute function, that’s what is causing the problem

daring prairie
#

no, i think you should look at the guide i sent on event handling