Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
DiscordJS v13 Cannot read properties of undefined (reading 'channels')

Code:

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] })
}

When adding a banner to the server it gives the error Unhandled Rejection: TypeError: Cannot read properties of undefined (reading 'channels')

The other logging files have the exact same line of code const logChannel = await client.channels.cache.get(config.log_channel_id); and it works fine

Adding console.log(client) before const logChannel returns undefined

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This code below works after we troubleshot the issue.

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]
    });
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda