Reputation: 13
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");
})
Upvotes: 0
Views: 55
Reputation: 468
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.
Upvotes: 2