Somehow getting forum posts from a completely unrelelated forum channel

I have a utility function to fetch threads from a forum channel
export async function fetch_all_threads_archive_count(forum: Discord.ForumChannel, count: number) {
const threads = new Discord.Collection([
...await fetch_active_threads(forum),
...await fetch_inactive_threads_count(forum, count)
]);
return threads;
}
export async function fetch_all_threads_archive_count(forum: Discord.ForumChannel, count: number) {
const threads = new Discord.Collection([
...await fetch_active_threads(forum),
...await fetch_inactive_threads_count(forum, count)
]);
return threads;
}
Somehow this utility is giving me a completely unrelated forum post though:
// ...
const threads = await fetch_all_threads_archive_count(forum, cleanup_limit);
M.debug("Cleaning up", threads.size, "threads in", forum.name);
for(const [ _, thread ] of threads) {
M.debug(thread.name, thread.parentId, forum.id, forum.name);
assert(thread.parentId && thread.parentId == forum.id);
...
}
// ...
const threads = await fetch_all_threads_archive_count(forum, cleanup_limit);
M.debug("Cleaning up", threads.size, "threads in", forum.name);
for(const [ _, thread ] of threads) {
M.debug(thread.name, thread.parentId, forum.id, forum.name);
assert(thread.parentId && thread.parentId == forum.id);
...
}
I'm getting an output of Git 1124619767542718524 1013107104678162544 forum-a. The thread "Git" is from a channel called resources, not forum-a. I have no idea how it got here. I have no idea why the parent id could be different. The functions the utility calls
export async function fetch_active_threads(forum: Discord.ForumChannel) {
const { threads } = await forum.threads.fetchActive();
return threads;
}

export async function fetch_inactive_threads_count(forum: Discord.ForumChannel, count: number) {
let before: string | undefined = undefined;
const thread_entries: [string, Discord.ThreadChannel][] = [];
while(true) {
const { threads, hasMore } = await forum.threads.fetchArchived({ before, limit: Math.min(count, 100) });
thread_entries.push(...threads);
// The type annotation is needed because of a typescript bug
// https://github.com/microsoft/TypeScript/issues/51115
const last: Discord.ThreadChannel = threads.last()!;
before = last.id;
count -= threads.size;
if(!hasMore || count <= 0) {
break;
}
}
return new Discord.Collection(thread_entries);
}
export async function fetch_active_threads(forum: Discord.ForumChannel) {
const { threads } = await forum.threads.fetchActive();
return threads;
}

export async function fetch_inactive_threads_count(forum: Discord.ForumChannel, count: number) {
let before: string | undefined = undefined;
const thread_entries: [string, Discord.ThreadChannel][] = [];
while(true) {
const { threads, hasMore } = await forum.threads.fetchArchived({ before, limit: Math.min(count, 100) });
thread_entries.push(...threads);
// The type annotation is needed because of a typescript bug
// https://github.com/microsoft/TypeScript/issues/51115
const last: Discord.ThreadChannel = threads.last()!;
before = last.id;
count -= threads.size;
if(!hasMore || count <= 0) {
break;
}
}
return new Discord.Collection(thread_entries);
}
What's happening?
2 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
jr
jr11mo ago
Thanks! If discord js isn’t doing that currently, is a patch needed somewhere? Thanks