tamarok
tamarok
DIdiscord.js - Imagine ❄
Created by tamarok on 1/18/2025 in #djs-questions
Listing entries in a ForumChannel?
Turns out the issue was archived threads. This works for me, as a test bed:
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);
}
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);
}
6 replies
DIdiscord.js - Imagine ❄
Created by tamarok on 1/18/2025 in #djs-questions
Listing entries in a ForumChannel?
I had looked at this, but it only returns one thread. Not the list of threads in the channel.
6 replies
DIdiscord.js - Imagine ❄
Created by tamarok on 10/6/2023 in #djs-questions
Processing message before notification?
That’s what I thought. Thanks for the confirmation.
5 replies