async function displayThreads (threads: AnyThreadChannel[]) {
for (let i = 0; i < threads.length; i++) {
const messages = await threads[i].messages.fetch();
console.log('Name:', threads[i].name, `(msg count: ${messages.size})`);
messages.forEach(message => {
console.log('-', message.content);
});
}
}
async function listForumThreads (channelId: string, since?: Date) {
const client = await getClient();
const channel = client.channels.cache.get(channelId) as Channel;
if (channel?.type === ChannelType.GuildForum) {
console.log('Channel:', channel.name);
console.log('Topic:', channel.topic);
const forumChannel = channel as ForumChannel;
const threadCacheA = await forumChannel.threads.fetchActive(false);
const theadForumChannelsA = Array.from(threadCacheA.threads.entries());
console.log('XX', theadForumChannelsA.length);
displayThreads(Array.from(threadCacheA.threads.entries()).map(entry => entry[1]));
const threadCacheB = await forumChannel.threads.fetchActive(true);
const theadForumChannelsB = Array.from(threadCacheB.threads.entries());
console.log('YY', theadForumChannelsB.length);
displayThreads(Array.from(threadCacheB.threads.entries()).map(entry => entry[1]));
const threadCacheC = await forumChannel.threads.fetchArchived({ fetchAll: true });
const theadForumChannelsC = Array.from(threadCacheC.threads.entries());
console.log('ZZ', theadForumChannelsC.length);
displayThreads(Array.from(threadCacheC.threads.entries()).map(entry => entry[1]));
}
process.exit(1);
}