DukeZero
DukeZero

Reputation: 11

Discord.js: member.guild.channels.find is not a function

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

Answers (4)

Lor4nd
Lor4nd

Reputation: 1

const channel = member.guild.channels.cache.find(channel => channel.name === 'welcome');

Upvotes: 0

Joe Moore
Joe Moore

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

Ramiz Wachtler
Ramiz Wachtler

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

Aplet123
Aplet123

Reputation: 35560

You typed member.guild.channel.find. Change it to member.guild.channels.cache.find, since it was changed a while ago. See the docs for more info.

Upvotes: 5

Related Questions