From 0186244e59d14b132d39ecf5f5e75c7d2d487c97 Mon Sep 17 00:00:00 2001 From: Ayfri Date: Tue, 10 Aug 2021 05:48:21 +0200 Subject: [PATCH] docs: Add information about fetching only active threads. --- src/Fetcher.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Fetcher.ts b/src/Fetcher.ts index 93dc7c6..0c4f673 100644 --- a/src/Fetcher.ts +++ b/src/Fetcher.ts @@ -1,4 +1,4 @@ -import {Channel, Client, Collection, Guild, Message, NewsChannel, Permissions, Snowflake, TextChannel, ThreadChannel} from 'discord.js'; +import {Client, Collection, Guild, Message, NewsChannel, Permissions, Snowflake, TextChannel, ThreadChannel} from 'discord.js'; import {EventEmitter} from 'events'; @@ -58,7 +58,7 @@ export class Fetcher extends EventEmitter { * Fetch the entire list of messages from a channel, can be long and makes you have rateLimits. * * @param channelID - The channel, can be an ID or a Channel. - * @param threads - If set to `true` it will fetch its threads. + * @param threads - If set to `true` it will fetch its threads, for now it will only fetch the active threads. * @returns The messages fetched. */ public async fetchChannel(channelID: Snowflake | FetchChannel, threads: boolean = false) { @@ -68,9 +68,8 @@ export class Fetcher extends EventEmitter { if (this.isFetchChannel(channel)) { this.emit('fetchChannel', channel); this.fetching = true; - let channelMessages = await channel.messages.fetch({ - limit: 100, - }); + let channelMessages = await channel.messages.fetch({limit: 100}); + this.emit('fetch', channelMessages.size, channelMessages); while (channelMessages.size > 0) { @@ -97,7 +96,7 @@ export class Fetcher extends EventEmitter { * Fetch an array of Snowflakes or TextChannels or a collection of TextChannels. * * @param channels - The channels to fetch. - * @param threads - If set to `true` it will fetch all the threads of all the channels. + * @param threads - If set to `true` it will fetch all the threads of all the channels, for now it will only fetch the active threads. * @returns - The messages fetched. */ public async fetchChannels(channels: Array | Collection, threads: boolean = false) { @@ -121,7 +120,7 @@ export class Fetcher extends EventEmitter { * Can be really long and you should prefer using events than waiting for it to finish. * * @param guildID - The guild to fetch, can be an ID or a Guild. - * @param threads - If set to `true` it will fetch all the threads of the guild. + * @param threads - If set to `true` it will fetch all the threads of the guild, for now it will only fetch the active threads. * @returns The messages fetched. */ public async fetchGuild(guildID: Snowflake | Guild, threads: boolean = false) { @@ -167,9 +166,8 @@ export class Fetcher extends EventEmitter { this.fetching = true; this.emit('fetchThread', thread, thread.parent); - let threadMessages = await thread.messages.fetch({ - limit: 100, - }); + let threadMessages = await thread.messages.fetch({limit: 100}); + this.emit('fetch', threadMessages.size, threadMessages); while (threadMessages.size > 0) { @@ -193,11 +191,12 @@ export class Fetcher extends EventEmitter { public async fetchThreads(threadsIDs: Array | Collection, channelID: Snowflake | FetchChannel): Promise>; /** * Fetch the entire list of messages from multiple threads or all the threads of a channel or all threads of a guild. - * + * For now it will only fetch the active threads. + * * @remarks * If one of the thread is private, it will need the `MANAGE_THREADS` permission to be able to fetch its messages. * - * @params threadsIDs - A list or a collection of threads or snowflakes to fetch messages from, if snowflakes are provided, you will need the second argument, or a channel where it will fetch all its channels, or a guild where it will fetch all its threads from all its channels. + * @param threadsIDs - A list or a collection of threads or snowflakes to fetch messages from, if snowflakes are provided, you will need the second argument, or a channel where it will fetch all its channels, or a guild where it will fetch all its threads from all its channels. * @param channelID - The channel ID or the Channel itself parant to all the threads passed as snowflakes, it will fetch the threads from this channel. * @returns - All the messages fetched. */