I've been trying to make a welcome embed for a Discord.js bot. My problem is, that I keep getting the error:
TypeError: Cannot read properties of undefined (reading 'cache')
If I modify guild to guilds then I get this error:
TypeError: Cannot read properties of undefined (reading 'get')
I'm trying to display the amount of members in the guild (server). However, this error is preventing me. I've tried googling but I am unable to find any solutions, so I came here. I am using Discord.js v13.6 (the latest version).
The code is supposed to show an embed, when a member joins the guild. Here, of course, is my code:
const { MessageEmbed } = require('discord.js');
module.exports = {
name: 'guildMemberAdd',
once: false,
execute(member) {
console.log('New member joined')
const WelcomeChannel = '941373101277589564'
const guild = member.guilds.cache.get('940180806696058910')
const channel = member.guilds.channels.cache.get(WelcomeChannel)
let welcomeEmbed = new MessageEmbed()
.setDescription(`Welcome <@${member.user.id}> to the **Monocle Games** Discord server.\n Member Count: ${guild.memberCount} `)
.setTimestamp()
welcomeEmbed.setAuthor({
name: '**WELCOME**',
iconURL: member.user.avatarURL()
})
channel.send({embeds: [welcomeEmbed]})
}
}
It is part of an event handler, however that is not related to the problem. My first thought was that the way I was getting the guild was outdated, however, I do believe this is the latest version, so what am I doing wrong?
Member has guild property:
const guild = member.guild
const channel = guild.channels.cache.get(WelcomeChannel)