简体   繁体   中英

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?

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.

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

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 - ie message.user.avatarURL() as it is a function.

Let me know if this works

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM