Cannot read property 'send' or undefined :/

Hey, in my ready.js, I made a script when my bot joins a new server or leave, I have informations to the server in a channel, but the console say "cannot read property ‘send’ or undefined.
My code:
const Discord = require(‘discord.js’);
const client = new Discord.Client();
const logsChannel = client.channels.cache.get(‘815953311614107709’);

module.exports = (client) => {
console.log(‘Synapse en live !’);
client.user.setActivity(‘s!help’, { type: ‘WATCHING’ });

client.on(‘guildCreate’, (guild) => {
console.log("Joined a new guild: " + guild.name);
const joinEmbed = new Discord.MessageEmbed()
.setTitle(Omg, je suis arrivé sur un nouveau serveur !)
.addField(Serveur, ${guild.name})
.addField(Fondateur, ${guild.owner})
.addField(Nombre de membres, ${guild.memberCount} membres)
.setFooter(Je suis actuellement sur ${client.guilds.cache.size} serveurs !)
.setTimestamp()
.setColor(‘GREEN’)
logsChannel.send(joinEmbed);
})

client.on(‘guildDelete’, (guild) => {
console.log("Left a guild: " + guild.name);
const leaveEmbed = new Discord.MessageEmbed()
.setTitle(Oh nan, je viens de quitter un serveur :/)
.addField(Serveur, ${guild.name})
.addField(Fondateur, ${guild.owner})
.addField(Nombre de membres, ${guild.memberCount} membres)
.setFooter(Je suis actuellement sur ${client.guilds.cache.size} serveurs !)
.setTimestamp()
.setColor(‘RED’)
logsChannel.send(leaveEmbed);
})
};

Errors are at:
logsChannel.send(joinEmbed);
logsChannel.send(leaveEmbed);

the logsChannel variable is undefined, meaning the client channel cache get could not find the channel in its bot cache. try client.channels.fetch('815953311614107709') instead of client.channels.cache.get.

2 Likes