From 99041671f0d9bbf8756b251e1bbb61aa03628a60 Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Wed, 9 May 2018 16:28:40 +0200 Subject: [PATCH] feat(GuildChannel): add fetchInvites method Backported from commit: 47bc0fc51e937f036a71d477f56fa884d44ee92d PR: #2339 --- src/structures/GuildChannel.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/structures/GuildChannel.js b/src/structures/GuildChannel.js index b18e972e7..3842f2b96 100644 --- a/src/structures/GuildChannel.js +++ b/src/structures/GuildChannel.js @@ -4,6 +4,7 @@ const PermissionOverwrites = require('./PermissionOverwrites'); const Permissions = require('../util/Permissions'); const Collection = require('../util/Collection'); const Constants = require('../util/Constants'); +const Invite = require('./Invite'); /** * Represents a guild channel (i.e. text channels and voice channels). @@ -332,6 +333,24 @@ class GuildChannel extends Channel { .then(channel => withTopic ? channel.setTopic(this.topic) : channel); } + /** + * Fetches a collection of invites to this guild channel. + * Resolves with a collection mapping invites by their codes. + * @returns {Promise>} + */ + fetchInvites() { + return this.client.rest.makeRequest('get', Constants.Endpoints.Channel(this.id).invites, true) + .then(data => { + const invites = new Collection(); + for (let invite of data) { + invite = new Invite(this.client, invite); + invites.set(invite.code, invite); + } + + return invites; + }); + } + /** * Deletes this channel. * @param {string} [reason] Reason for deleting this channel