#guildMemberAdd not working (FYI i've enabled the intents within Discord Developer)

12 messages · Page 1 of 1 (latest)

stable knoll
#

As title states

red sand
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

acoustic furnace
#

There is almost no information to work with here

stable knoll
#
const { Events } = require("discord.js");
const newJoinedUser = require("../schemas/userSchema.js");

module.exports = {
    name: Events.GuildMemberAdd,
    once: false,
    execute(member) {
        if(member.permissions.has(PermissionsBitField.Flags.Administrator)){
            isAdministrator = true;
        } 
        else {
            isAdministrator = false;
        }
        const newJoinedUser = new userJoined({
            discordUsername: member.user.username,
            discordGuild: member.guild.name,
            joinedOn: member.joinedAt,
            isAdministrator: false,
        });
        newJoinedUser.save();
    },
};
#

this isnt working

#

guildmemberadd isnt workign

void creek
#

Please share your Client construction

stable knoll
#
const fs = require('node:fs');
const path = require('node:path');
const newJoinedUser = require('./schemas/userSchema.js')

require('dotenv').config();
const {
    Client,
    Collection,
    Events,
    GatewayIntentBits,
    PermissionsBitField,
    ChannelType,
    EmbedBuilder,
    ActionRowBuilder,
    ButtonBuilder,
    ButtonStyle,
} = require('discord.js');

// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs
    .readdirSync(eventsPath)
    .filter((file) => file.endsWith('.js'));

for (const file of eventFiles) {
    const filePath = path.join(eventsPath, file);
    const event = require(filePath);
    if (event.once) {
        client.once(event.name, (...args) => event.execute(...args));
    }
    else {
        client.on(event.name, (...args) => event.execute(...args));
    }
}

client.commands = new Collection();

const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs
    .readdirSync(commandsPath)
    .filter((file) => file.endsWith('.js'));

for (const file of commandFiles) {
    const filePath = path.join(commandsPath, file);
    const command = require(filePath);
    // Set a new item in the Collection with the key as the command name and the value as the exported module
    if ('data' in command && 'execute' in command) {
        client.commands.set(command.data.name, command);
    }
    else {
        console.log(
            `[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`,
        );

client.on(Events.GuildMemberAdd, async (member) => {
    const newJoinedUser = new userJoined({
        discordUsername: member.user.username,
        discordGuild: member.guild.name,
        joinedOn: new Date().toLocaleDateString(),
    });

    await newJoinedUser.save();
});

void creek
stable knoll
#

which intent does it fall under

#

for me to add

void creek
#

GuildMembers