0

how can code a discord bot to private chat a new user that just join my server. this is my code but not working

client.on('guildMemberAdd', member =>{
    member.send("welcome to this server");
})
  • Does this answer your question? [None of my discord.js guildmember events are emitting, my user caches are basically empty, and my functions are timing out?](https://stackoverflow.com/questions/64559390/none-of-my-discord-js-guildmember-events-are-emitting-my-user-caches-are-basica) – MrMythical Mar 02 '22 at 15:38

1 Answers1

2

Your code looks fine, but you need to check to see if you have the right guild intents.

// Make sure you have Intents.FLAGS.GUILDS and Intents.FLAGS.GUILD_MEMBERS
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS] });

Then you should be able to add the listener.

client.on('guildMemberAdd', member =>{
    member.send("Welcome to Sparta!");
})

Privileged Gateway Intents Also, this is a privileged intent, so you have to make sure you are allowing it in the Discord Developer Portal. To do that, navigate to Developer Portal>Select your bot> Select "Bot" (instead of General Information) > Enable Privileged Gateway Intents: Members.

JeremiahDuane
  • 374
  • 4
  • 15