mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 17:30:07 +00:00
18 lines
748 B
TypeScript
18 lines
748 B
TypeScript
import { BotWithCache } from "../../cache/src/addCacheCollections.ts";
|
|
import { BigString } from "../deps.ts";
|
|
|
|
/** Fetch members for an entire guild then return the entire guilds cached members. */
|
|
export async function fetchAndRetrieveMembers(bot: BotWithCache, guildId: BigString) {
|
|
if (!bot.enabledPlugins?.has("CACHE")) {
|
|
throw new Error("The fetchAndRetrieveMembers function requires the CACHE plugin first.");
|
|
}
|
|
|
|
const guild = bot.guilds.get(bot.transformers.snowflake(guildId));
|
|
if (!guild) {
|
|
throw new Error("The guild was not found in cache. Unable to fetch members for uncached guild.");
|
|
}
|
|
|
|
await bot.helpers.fetchMembers(guildId, { limit: 0 });
|
|
return bot.members.filter((member) => member.guildId === guildId);
|
|
}
|