Skip to content

Commit

Permalink
docs: Add information about fetching only active threads.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayfri committed Aug 10, 2021
1 parent db10cf3 commit 0186244
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/Fetcher.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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<Snowflake | FetchChannel> | Collection<Snowflake, FetchChannel>, threads: boolean = false) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -193,11 +191,12 @@ export class Fetcher extends EventEmitter {
public async fetchThreads(threadsIDs: Array<Snowflake> | Collection<Snowflake, Snowflake>, channelID: Snowflake | FetchChannel): Promise<Collection<Snowflake, Message>>;
/**
* 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.
*/
Expand Down

0 comments on commit 0186244

Please sign in to comment.