#Can't send message to specific channels

12 messages · Page 1 of 1 (latest)

steady portal
#

In my ClientReady event. I can send a message to specific channel

const notiChannel = client.channels.cache.get('1379862671217791069');

notiChannel.send({ 
    embeds: [notiEmbed]
});

but it seems not to work with this slash command

const notiChannel = client.channels.cache.get('1379778222169784431');
const publicNotiChannel = client.channels.cache.get('1374718357953183804');

try {
    const notificationEmbed = new EmbedBuilder()
    // ...

    if (notiChannel) {
        await notiChannel.send({ embeds: [notificationEmbed] });
    }
                            
    if (publicNotiChannel) {
        const publicMessage = await publicNotiChannel.send({ embeds: [notificationEmbed] });
        await publicMessage.react('👋🏻');
    }
} catch (error) {
    console.error('Error : '+ error.message);
}

it throws: Cannot read properties of undefined (reading 'channels')

daring hullBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
hollow mango
#

show the full code of your ready event listener

#

because client is apparently undefined according to your error

steady portal
# hollow mango show the full code of your ready event listener

here

const { Events, EmbedBuilder } = require('discord.js');

module.exports = {
    name: Events.ClientReady,
    once: true,
    execute(client) {
        console.log(`✅ Logged in : ${client.user.tag} (${client.user.id})`);

        const notiChannel = client.channels.cache.get('1379862671217791069');

        const notiEmbed = new EmbedBuilder()
            .setDescription("## ✅ **บอทเริ่มทำงานแล้ว**")
            .setColor("#84cc16")
            .setFooter({
                text: "Arena Breakout Assistance#3107",
                iconURL: "https://media.discordapp.net/attachments/1376182983433781349/1380066711893442610/favicon-512x512.png?ex=684286c8&is=68413548&hm=bac15f1ac366e6b384187b5499d7e6dbe974b2f29340e68c326cb34db2807d31&=&format=webp&quality=lossless&width=576&height=576",
            })
            .setTimestamp();

        notiChannel.send({ 
            embeds: [notiEmbed]
        });
    },
};
hollow mango
#

and how do you register your event listeners? what's the handler?

steady portal
#

I'm using the one that on the document

const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
    const filePath = path.join(eventsPath, file);
    const event = require(filePath);
    
    if (event.once) {
        client.once(event.name, (...args) => event.execute(...args));
    } else {
        client.on(event.name, (...args) => event.execute(...args));
    }
}
hollow mango
#

console.log(`:white_check_mark: Logged in : ${client.user.tag} (${client.user.id})`);does that line show up in your console?

hollow mango
#

post the full error you receive including stack

steady portal
# hollow mango post the full error you receive including stack
Kick error: TypeError: Cannot read properties of undefined (reading 'channels')
at Object.execute (d:\Works\Discord Bots\abith\src\commands\moderation\kick.js:143:52)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Object.execute (d:\Works\Discord Bots\abith\src\events\interactionCreate.js:16:13)
hollow mango
#

at Object.execute (d:\Works\Discord Bots\abith\src\commands\moderation\kick.js:143:52)
not anywhere close to your ready listener. please pay attention to your errors, they have a lot of useful information