4

I have a code where if someone joins the bot gives a welcome message but when a user joins, the bot does not give the welcome message.

Code:

bot.on('guildMemberAdd', member => {

    const channel = member.guild.channels.cache.find(channel => channel.name === "general")
    if (!channel) return;

    const joinembed = new Discord.MessageEmbed()
    .setTitle(`A new member just arrived!`)
    .setDescription(`Welcome ${member} we hope you enjoy your stay here!`)
    .setColor("#FF0000")

    channel.send(joinembed)
});

My bot has all the permissions and is at the very top of the role hierarchy, please help I don't know what am I doing wrong. This problem also applies when the user leaves (It also does not give the welcome message)

Wide
  • 339
  • 2
  • 6
  • 18

1 Answers1

23

Discord made some changes a few days ago. The bot is not sending the welcome message because it never gets the guildMemberAdd event. From now on to get these types of events you will have to turn the intents on in the dev portal. After doing this your code will start working again.

dev portal

Nicolas Hevia
  • 15,143
  • 4
  • 22
  • 31
Shubham Parihar
  • 638
  • 5
  • 11
  • Did you get that working? Because it's not working for me and I've done that.... =] – taxilian Jan 13 '23 at 02:27
  • @taxilian make sure you are requesting those intents on bot startup too. The PHP discord bot uses the ```getDefaultIntents()``` which excludes the presence/guild members intents ```return static::getAllIntents() & ~(static::GUILD_MEMBERS | static::GUILD_PRESENCES | static::MESSAGE_CONTENT);``` – QuantumBlack Mar 14 '23 at 14:36
  • Yeah I made some changes to how I was initializing things and now it's working for me, but I'm not actually certain what I changed. I thought I was doing that before =] – taxilian Mar 15 '23 at 15:21