mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
feat(plugins/helpers): fetchAndRetrieveMembers (#2035)
This commit is contained in:
@@ -18,9 +18,14 @@ import { archiveThread, editThread, lockThread, unarchiveThread, unlockThread }
|
||||
import { disconnectMember } from "./src/disconnectMember.ts";
|
||||
import { getMembersPaginated } from "./src/getMembersPaginated.ts";
|
||||
import { moveMember } from "./src/moveMember.ts";
|
||||
import { fetchAndRetrieveMembers } from "./src/fetchAndRetrieveMembers.ts";
|
||||
import { BotWithCache } from "../cache/src/addCacheCollections.ts";
|
||||
|
||||
export interface BotWithHelpersPlugin extends Bot {
|
||||
helpers: FinalHelpers & {
|
||||
fetchAndRetrieveMembers: (
|
||||
guildId: bigint,
|
||||
) => Promise<Collection<bigint, DiscordenoMember>>;
|
||||
sendDirectMessage: (
|
||||
userId: bigint,
|
||||
content: string | CreateMessage,
|
||||
@@ -70,6 +75,9 @@ export interface BotWithHelpersPlugin extends Bot {
|
||||
export function enableHelpersPlugin(rawBot: Bot): BotWithHelpersPlugin {
|
||||
const bot = rawBot as BotWithHelpersPlugin;
|
||||
|
||||
bot.helpers.fetchAndRetrieveMembers = (
|
||||
guildId: bigint,
|
||||
) => fetchAndRetrieveMembers(bot as unknown as BotWithCache, guildId);
|
||||
bot.helpers.sendDirectMessage = (
|
||||
userId: bigint,
|
||||
content: string | CreateMessage,
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { BotWithCache } from "../../cache/src/addCacheCollections.ts";
|
||||
|
||||
/** Fetch members for an entire guild then return the entire guilds cached members. */
|
||||
export async function fetchAndRetrieveMembers(bot: BotWithCache, guildId: bigint) {
|
||||
if (!bot.enabledPlugins?.has("CACHE")) {
|
||||
throw new Error("The fetchAndRetrieveMembers function requires the CACHE plugin first.");
|
||||
}
|
||||
|
||||
const guild = bot.guilds.get(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, guild.shardId);
|
||||
return bot.members.filter((member) => member.guildId === guildId);
|
||||
}
|
||||
Reference in New Issue
Block a user