#guildMemberAdd not working (FYI i've enabled the intents within Discord Developer)
12 messages · Page 1 of 1 (latest)
• 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.
There is almost no information to work with here
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
Please share your Client construction
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();
});
You have enabled access to the GuildMembers intent in the dev portal, but you still need to add it in your Client intents in your code
GuildMembers