i was coding my welcome message on my discord bot, but when someone enters in the server, console give me this error:
TypeError: Cannot read properties of undefined (reading 'cache')
here is my guildMemberAdd.js code:
const { MessageEmbed } = require('discord.js');
module.exports = {
name: "guildMemberAdd",
execute(member) {
const MemberRole = member.guild.roles.cache.get('891716789879316540');
member.roles.add(MemberRole);
const WelcomeEmbed = new MessageEmbed()
.setColor('RANDOM')
.setAuthor('WELCOME', member.user.displayAvatarURL({dynamic: true}))
.setDescription(`Welcome ${member} in our server!\n you are the number ${member.guild.memberCount}`)
.setFooter(`${member.user.tag}`, member.user.displayAvatarURL({dynamic: true}))
.setTimestamp();
member.guild.channel.cache.get('768526997882142743').send({content: `${member}`, embeds: [WelcomeEmbed]});
const LogEmbed = new MessageEmbed()
.setColor('GREEN')
.setDescription(`${member} came in our server`)
.setTimestamp();
member.guild.channel.cache.get('768526997882142743').send({embeds: [LogEmbed]});
}
}
the strange thing is that on the 6th line it works fine, but in the 15th line and in the 22th doesn't works
CodePudding user response:
Simple typo in channel
:
member.guild.channel.cache.get('768526997882142743')
Should be:
member.guild.channels.cache.get('768526997882142743')