threads issue

guild.threads.cache.forEach((thread) => {
^

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));
});
});
Was this page helpful?