Reputation: 17
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
Upvotes: 1
Views: 811
Reputation: 124
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.
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)
})
}
Upvotes: 1