Cannot read properties of undefined (reading 'send')

I'm awaiting the ready event from my bot to send a message. Sadly that doesn't work. Any ideas?
(async () => {
try {
await ready;
client.channels.cache.get(channelID).send({ content: " ", embeds: [embed_events] }).then(sent => {
databases.overview.message_id = sent.id;
});
} catch (err) {
console.error(err);
}
})();
(async () => {
try {
await ready;
client.channels.cache.get(channelID).send({ content: " ", embeds: [embed_events] }).then(sent => {
databases.overview.message_id = sent.id;
});
} catch (err) {
console.error(err);
}
})();
Error:
TypeError: Cannot read properties of undefined (reading 'send')
TypeError: Cannot read properties of undefined (reading 'send')
9 Replies
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Syjalo
Syjalo17mo ago
1. Invalid channel id 2. Channel is not cached
Schlaumeyer
Schlaumeyer17mo ago
Channel ID is correct. How can I see if the channel is cached? Or fix that?
Syjalo
Syjalo17mo ago
Is that a guild channel?
Schlaumeyer
Schlaumeyer17mo ago
It's a channel in a discord server, if you mean that, yes. The bot also has access to it (it has administrator permissions)
Syjalo
Syjalo17mo ago
Do you have Guilds intent?
Schlaumeyer
Schlaumeyer17mo ago
I guess so
const client = new Client({ intents: ['Guilds', 'GuildMessages'] });
const client = new Client({ intents: ['Guilds', 'GuildMessages'] });
Syjalo
Syjalo17mo ago
What is in your ready variable?
Schlaumeyer
Schlaumeyer17mo ago
Promise { undefined }
const ready = new Promise((resolve) => {
client.on('ready', () => resolve());
});

export { ready };

(async () => {
try {
await ready;
console.log(ready)
console.log(`Eingeloggt als ${client.user.tag}`);
} catch (err) {
console.error(err);
}
})();
const ready = new Promise((resolve) => {
client.on('ready', () => resolve());
});

export { ready };

(async () => {
try {
await ready;
console.log(ready)
console.log(`Eingeloggt als ${client.user.tag}`);
} catch (err) {
console.error(err);
}
})();
That's the index.js file. I'm importing ready in another file and wait that I can send a message