1

I have been half following a tutorial, half working it out on my own how to code a discord bot in discord.js. I am up to the point where i want to add a welcome message, and after doing the same thing as the person making the tutorial the code isn't console logging a joining member to the server. Here is the code that i have done, and in the tutorial the code would send a welcome message to the selected channel and console log the member.

there is no error message

module.exports = client => {
    const channelId = '790887807127650304' // welcome channel
    
    client.on('guildMemberAdd', member => {
        console.log(member)

        const message =  `welcome <@${member.id} to the server!`

        const channel = member.guild.channels.cache.get(channelID)
        channel.send(message)
    })
}

also, for reference, here is the tutorial i have been following; video

  • Have you turned on gateway intents? View reference [here](https://stackoverflow.com/questions/64559390/none-of-my-discord-js-guildmember-events-are-emitting-my-user-caches-are-basica/64559391#64559391) – Tyler2P Dec 22 '20 at 10:49

1 Answers1

1

Make sure the gateway intents are enabled in your dev portal for your bot, it's in the bot tab (the same page where you copy the bot's token). This is a change made after the tutorial you linked.

enter image description here

If you want to know why this is required, read this

Also there are a few errors in your code. You typed channelID two different ways and you didnt put '>' after <@${member.id}.

Here it is fixed.

module.exports = client => {
    const channelID = '790887807127650304' // welcome channel
    
    client.on('guildMemberAdd', member => {
        console.log(member)

        const message =  `welcome <@${member.id}> to the server!`

        const channel = member.guild.channels.cache.get(channelID)
        channel.send(message)
    })
}
Demeter29
  • 134
  • 9