6
votes

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.

5
well it seems your message doesn't have a proprety called channelLiora Haydont

5 Answers

15
votes

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"); 
});
1
votes
client.on('guildMemberAdd', member => {
client.on('message', 


var role = member.guild.roles.find('name', 'Beginner role name'); // Variable to get channel ID
member.addRole(role); // Adds the default role to members

member.guild.channels.get('JOIN/LEAVE Channel ID').send({embed: {
color: 3447003,
title: "**SERVER NAME** Welcome Bot!",
url: "WEBSITE URL",
description: "Welcome *" + member + "* to the **Server name** discord server!",
fields: [{
    name: "Information",
    value: "Some info on the server"
  }
],
timestamp: new Date(),
footer: {
  icon_url: client.user.avatarURL,
  text: "© NAME OF SERVER 2018 - 2019"
}
}}); });

Here is code that actually works :)

1
votes

I'm also making a welcome function for my bot here's the code, it seems to work great

//Welcome & goodbye messages\\
client.on('guildMemberAdd', member => {
    member.roles.add(member.guild.roles.cache.find(i => i.name === 'Among The Server'))

    const welcomeEmbed = new Discord.MessageEmbed()

    welcomeEmbed.setColor('#5cf000')
    welcomeEmbed.setTitle('**' + member.user.username + '** is now Among Us other **' + member.guild.memberCount + '** people')
    welcomeEmbed.setImage('https://cdn.mos.cms.futurecdn.net/93GAa4wm3z4HbenzLbxWeQ-650-80.jpg.webp')

    member.guild.channels.cache.find(i => i.name === 'greetings').send(welcomeEmbed)
})

client.on('guildMemberRemove', member => {
    const goodbyeEmbed = new Discord.MessageEmbed()

    goodbyeEmbed.setColor('#f00000')
    goodbyeEmbed.setTitle('**' + member.user.username + '** was not the impostor there are **' + member.guild.memberCount + '** left Among Us')
    goodbyeEmbed.setImage('https://gamewith-en.akamaized.net/article/thumbnail/rectangle/22183.png')

    member.guild.channels.cache.find(i => i.name === 'greetings').send(goodbyeEmbed)
})
//Welcome & goodbye messages end\\
1
votes

my code is

bot.on('guildMemberAdd', async member => {
    const channel = member.guild.channels.cache.get('channel-id-here');
    if (!channel) return;

    channel.send("text-here!")
});

hope it workes!

-3
votes

Or use this for embeds.

client.on('guildMemberAdd', msg => { // Commands Go Inside The client.on('message', 
msg => )
msg.guild.channels.get('484648408372740099').send({embed: {
color: 3447003,
author: {
  name: client.user.username,
  icon_url: client.user.avatarURL
},
title: "Welcome To ()!",
url: "https://districtservices.net",
description: "@MEMBER",
fields: [{
    name: "Fields",
    value: "They can have different fields with small headlines."
  },
  {
    name: "Masked links",
    value: "You can put [masked links](http://google.com) inside of rich embeds."
  },
  {
    name: "Markdown",
    value: "You can put all the *usual* **__Markdown__** inside of them."
  }
],
timestamp: new Date(),
footer: {
  icon_url: client.user.avatarURL,
  text: "© Example"
}

}}); });