From b264a8943e6241d993759491d0e32d0acd778725 Mon Sep 17 00:00:00 2001 From: Ayfri Date: Sat, 21 Aug 2021 03:41:57 +0200 Subject: [PATCH] feat: Add fetchGuilds method #15. --- src/Fetcher.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Fetcher.ts b/src/Fetcher.ts index b735b2b..48b790a 100644 --- a/src/Fetcher.ts +++ b/src/Fetcher.ts @@ -134,6 +134,26 @@ export class Fetcher extends EventEmitter { return messages; } + /** + * Fetch all the guilds provided, if not all the guilds in the cache of the {@link client}. + * + * @param threads - If set to `true` it will fetch all the threads of the guilds, for now it will only fetch the active threads. + * @returns - The messages fetched. + */ + public async fetchGuilds(threads?: boolean): Promise>; + public async fetchGuilds(guilds: Collection | Array, threads: boolean): Promise>; + public async fetchGuilds(guilds?: Collection | Array | boolean, threads: boolean = false) { + const guildList = guilds instanceof Collection ? [...guilds.values()] : guilds instanceof Array ? guilds : [...this.client.guilds.cache.values()]; + const fetchThreads = typeof guilds === 'boolean' ? guilds : threads ?? false; + let messages = new Collection(); + for (const guild of guildList) { + const guildMessages = await this.fetchGuild(guild, fetchThreads); + messages = messages.concat(guildMessages); + } + + return messages; + } + public async fetchThread(thread: ThreadChannel): Promise>; public async fetchThread(threadID: Snowflake, channelID: Snowflake | FetchChannel): Promise>; /**