Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!