threads issue
guild.threads.cache.forEach((thread) => {
^
TypeError: Cannot read properties of undefined (reading 'cache')
code :
client.once('ready', () => {
console.log(
const guild = client.guilds.cache.get(guildId);
if (!guild) {
console.error(
return;
}
console.log(
guild.threads.cache.forEach((thread) => {
console.log(
thread.send(hardcodedMessage)
.then(() => console.log(
.catch((error) => console.error(
});
});
^
TypeError: Cannot read properties of undefined (reading 'cache')
code :
client.once('ready', () => {
console.log(
Logged in as ${client.user.tag});const guild = client.guilds.cache.get(guildId);
if (!guild) {
console.error(
Guild with ID ${guildId} not found.);return;
}
console.log(
Found guild: ${guild.name} (${guild.id}));guild.threads.cache.forEach((thread) => {
console.log(
Sending message to thread: ${thread.name} (${thread.id}));thread.send(hardcodedMessage)
.then(() => console.log(
Sent message to thread: ${thread.name})).catch((error) => console.error(
Error sending message to thread: ${thread.name}, error));});
});