'Welcome message when joining discord Server using discord.js
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.
Solution 1:[1]
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");
});
Solution 2:[2]
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 :)
Solution 3:[3]
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\\
Solution 4:[4]
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!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | iCodeAlot |
| Solution 3 | Suraj Rao |
| Solution 4 | tb3jesica |
