Skip to content

Bot isn’t listening to guildMemberAdd

I signed up just a few moments ago because something was really bothering me: I have the following code:

const Discord = require('discord.js');
const client = new Discord.Client();

client.on('guildMemberAdd', (member) => {
    console.log('New member.')
    const welcomeEmbed = new Discord.MessageEmbed()
    .setImage(member.user.avatarURL())
    .setColor('#e9fa2a')
    .setAuthor("Mangoly Assistant")
    .setTitle("New member in server")
    .setDescription('Welcome <@${member.id}> to the server! If you are new, please be sure to check out or rules channel and some useful links. We are glad to be having you here, everyone wave hello! :wave:')
    .setFooter('Created by kostis;#4464. || Mangoly Assistant')
    client.channels.cache.get('825130442197434418').send(welcomeEmbed)
});

client.once('ready', () => {
    console.log('Bot is ready')
})

client.login(nice try);

For some reason, when I leave and rejoin the server, the embed isn’t sending at all to the channel. I am getting no errors in the console. Any ideas on what may have gone wrong? Thanks. ๐Ÿ™‚

Answer

You need ‘Server Members Intent’ enabled when you invite the bot. Go to Discord Developer Portal > Bot > Scroll to bottom > make sure server members intent is checked server members intent box checked

You should also be able to enable it manually in your code, but idrk how to do it. I think itโ€™s like this:

//Client declaration
const client = new Discord.Client({
ws: {
intents: ['GUILD_MEMBERS']
}
})

Also, quick thing: to use ${variableHere} in a string, it must be a string with backticks ( ` ), like this:

var a = 'abc';
var b = '${a}d' //returns ${a}d
var c = `${a}d` //returns abcs