From 47bc0fc51e937f036a71d477f56fa884d44ee92d Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Tue, 13 Feb 2018 17:29:42 +0100 Subject: [PATCH] feat(GuildChannel): add fetchInvites method (#2339) * feat(GuildChannel): add fetchInvites method * fix: actually use the 'channels' endpoint --- src/structures/GuildChannel.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/structures/GuildChannel.js b/src/structures/GuildChannel.js index a79f11bae..324b6aeda 100644 --- a/src/structures/GuildChannel.js +++ b/src/structures/GuildChannel.js @@ -430,6 +430,21 @@ class GuildChannel extends Channel { .then(invite => new Invite(this.client, invite)); } + /** + * Fetches a collection of invites to this guild channel. + * Resolves with a collection mapping invites by their codes. + * @returns {Promise>} + */ + async fetchInvites() { + const inviteItems = await this.client.api.channels(this.id).invites.get(); + const invites = new Collection(); + for (const inviteItem of inviteItems) { + const invite = new Invite(this.client, inviteItem); + invites.set(invite.code, invite); + } + return invites; + } + /** * Clones this channel. * @param {Object} [options] The options