Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
41
rated 0 times [  45] [ 4]  / answers: 1 / hits: 7807  / 3 Years ago, sun, september 26, 2021, 12:00:00

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


More From » node.js

 Answers
7

Simple typo in channel:


member.guild.channel.cache.get('768526997882142743')

Should be:


member.guild.channels.cache.get('768526997882142743')

[#827] Saturday, September 18, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deiong

Total Points: 15
Total Questions: 103
Total Answers: 99

Location: Sudan
Member since Thu, May 7, 2020
4 Years ago
deiong questions
Mon, Nov 22, 21, 00:00, 3 Years ago
Tue, Jun 15, 21, 00:00, 3 Years ago
Mon, Dec 21, 20, 00:00, 3 Years ago
Thu, Oct 15, 20, 00:00, 4 Years ago
Tue, Jul 21, 20, 00:00, 4 Years ago
;