Skip to content

Commit

Permalink
feat: Add fetchChannels method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayfri committed Mar 21, 2021
1 parent 60660d2 commit 055bef8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ export class Fetcher extends EventEmitter {
}
return messages;
}

/**
* Fetch an array of Snowflakes or TextChannels or a collection of TextChannels.
* @param channels - The channels to fetch.
* @returns - The messages fetched.
*/
public async fetchChannels(channels: Array<Snowflake | TextChannel> | Collection<Snowflake, TextChannel>): Promise<Collection<Snowflake, Message>> {
if (channels instanceof Collection) channels = channels.array();
let messages = new Collection<Snowflake, Message>();

this.fetching = true;
for (const channel of channels) {
const channelMessages = await this.fetchChannel(channel);
messages = messages.concat(channelMessages);
}
this.fetching = false;

return messages;
}

/**
* Fetch an entire guild, fetching every TextChannels one by one because there is no other way.
Expand Down

0 comments on commit 055bef8

Please sign in to comment.