Welcome message when joining discord Server using discord.js

user9579257 picture user9579257 · Apr 10, 2018 · Viewed 53.2k times · Source

I am making a discord bot using node.js and discord.js, and I am currently trying to make it so that when a user joins the discord server, a custom welcome message is sent. Here is my code:

bot.on("guildMemberAdd" ,(message, member) => {
    message.channel.send("Welcome")
});

This is the error is get:

message.channel.send("Welcome")
                ^

TypeError: Cannot read property 'send' of undefined

Thanks for your help.

Answer

Skwal picture Skwal · Apr 10, 2018

If you read the documentation, there's is no message parameter, only member. You will have to get the guild's channel ID first.

Try something like this:

bot.on('guildMemberAdd', member => {
    member.guild.channels.get('channelID').send("Welcome"); 
});