Files
discordeno/plugins/bot/helpers/channels/threads/getActiveThreads.ts
T
Skillz4Killz ffe7cdbc6f feat: base plugin lib idea (#2308)
* feat: base plugin lib idea

* fix: stuff

* fmt

* fix: imports and exports

* fix: errors & tests

* fix: remove logs
2022-06-18 18:46:37 -04:00

28 lines
917 B
TypeScript

import { Bot } from "../../../bot.ts";
import { DiscordListActiveThreads } from "../../../deps.ts";
import { BotCollection as Collection } from "../../../util/collection.ts";
/** Returns all active threads in the guild, including public and private threads. Threads are ordered by their `id`, in descending order. */
export async function getActiveThreads(bot: Bot, guildId: bigint) {
const result = await bot.rest.runMethod<DiscordListActiveThreads>(
bot.rest,
"GET",
bot.constants.routes.THREAD_ACTIVE(guildId),
);
return {
threads: new Collection(
result.threads.map((t) => {
const thread = bot.transformers.channel(bot, { channel: t });
return [thread.id, thread];
}),
),
members: new Collection(
result.members.map((m) => {
const member = bot.transformers.threadMember(bot, m);
return [member.id, member];
}),
),
};
}