Código:
const config = require('../../config.json'); const Discord = require('discord.js'); module.exports = async(guild, bannerURL, client) => { const logChannel = await client.channels.cache.get(config.log_channel_id); if (!logChannel) return; const embed = new Discord.MessageEmbed() .setAuthor({ name: guild.name, iconURL: guild.iconURL() }) .setDescription(`**${guild.name} has banner now!**`) .setImage(bannerURL) .setColor(config.colour) .setTimestamp() return logChannel.send({ embeds: [embed] }) } Al agregar un banner al servidor, da el error Unhandled Rejection: TypeError: Cannot read properties of undefined (reading 'channels')
Los otros archivos de registro tienen exactamente la misma línea de código const logChannel = await client.channels.cache.get(config.log_channel_id); y funciona bien
Agregar console.log(client) antes const logChannel devuelve undefined
Este código a continuación funciona después de que solucionamos el problema.
banner.js
module.exports = { name: 'banner', description: 'emit update', devs: true, run: async (guild, message) => { guild.emit('guildBannerAdd', message.member); message.channel.send('Done ...'); }, };guildBannerAdd.js
const config = require('../../config.json') const Discord = require('discord.js') module.exports = async (client, member) => { const guild = client.guilds.cache.get(config.serverID) const logChannel = client.channels.cache.get(config.log_channel_id); if (!logChannel) return; const embed = new Discord.MessageEmbed() .setAuthor({ name: guild.name, iconURL: guild.iconURL() }) .setDescription(`**${guild.name} has banner now!**`) .setImage(guild.bannerURL()) .setColor(config.colour) .setTimestamp(); return logChannel.send({ embeds: [embed] }); }