Reputation: 11
So I'm trying to make a welcome message for my discord bot right now, but somehow I have a really weird problem where apparently members.guild.channels.find() is not a function.
client.on('guildMemberAdd', member =>{
const channel = member.guild.channels.find(channel => channel.name === "welcome");
if(!channel) return;
const welcomeEmbed = new Discord.MessageEmbed()
.setColor(pink)
.setAuthor('IdealBot', 'https://hypixel.net/attachments/ideal-png.1417277/', 'https://hypixel.net/threads/ideal-ideal-%E2%9D%96-level-52-%E2%9D%96-sweaty-skyblock-guild-%E2%9D%96-top-10-sb-guild-%E2%9D%96-splashes-%E2%9D%96-events-%E2%9D%96-recruiting.2500755/')
.setTitle('Welcome!')
.setDescription(`${member} just joined the discord! Make sure to read #rules!`)
.setThumbnail(message.user.avatarURL)
.setFooter('Note: The maximum amount of answers is 9.')
.setTimestamp();
channel.send(welcomeEmbed);
});
Yet when I try to run it, I get the error: TypeError: Cannot read property 'find' of undefined
I'm pretty sure I've used this before, does anybody know where this error could originate from?
Upvotes: 1
Views: 24576
Reputation: 1
const channel = member.guild.channels.cache.find(channel => channel.name === 'welcome');
Upvotes: 0
Reputation: 2023
I had this issue also, to solve it try member.guild.channels.find()
Also, the message.user.avatarURL will not work unless you have brackets - i.e message.user.avatarURL() as it is a function.
Let me know if this works
Upvotes: 1
Reputation: 5683
Hm, I guess the property you try to access does not exist. Looks like channels
must be used instead of channel
, see below:
const channel = member.guild.channels.find(channel => channel.name === "welcome");
Also see Welcome Message every X users example, there the property is as well accessed by .channels
Upvotes: 2