From a4d0ed16e788beb18074cfc6f0cc72f27c325d56 Mon Sep 17 00:00:00 2001 From: NotSugden Date: Sun, 19 Jan 2020 20:43:10 +0000 Subject: [PATCH] Add Guild#fetchBan and an error for not resolving the ID --- src/errors/Messages.js | 1 + src/structures/Guild.js | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/errors/Messages.js b/src/errors/Messages.js index ae42f73c5..857d4b868 100644 --- a/src/errors/Messages.js +++ b/src/errors/Messages.js @@ -71,6 +71,7 @@ const Messages = { SPLIT_MAX_LEN: 'Chunk exceeds the max length and contains no split characters.', BAN_RESOLVE_ID: (ban = false) => `Couldn't resolve the user ID to ${ban ? 'ban' : 'unban'}.`, + FETCH_BAN_RESOLVE_ID: 'Couldn\'t resolve the user ID to fetch.', PRUNE_DAYS_TYPE: 'Days must be a number', diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 987fa38f2..3ed254b34 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -554,6 +554,21 @@ class Guild extends Base { * @property {?string} reason Reason the user was banned */ + /** + * Fetches the information of a specific ban. + * @param {UserResolvable} user The User ID of the ban to fetch + * @returns {Promise} + */ + fetchBan(user) { + const id = this.client.users.resolveID(user); + if (!id) throw new Error('FETCH_BAN_RESOLVE_ID'); + return this.client.api.guilds(this.id).bans(id).get() + .then(ban => ({ + reason: ban.reason, + user: this.client.users.add(ban.user), + })); + } + /** * Fetches a collection of banned users in this guild. * @returns {Promise>} @@ -566,7 +581,7 @@ class Guild extends Base { user: this.client.users.add(ban.user), }); return collection; - }, new Collection()) + }, new Collection()), ); } @@ -584,7 +599,7 @@ class Guild extends Base { return this.client.api.guilds(this.id).integrations.get().then(data => data.reduce((collection, integration) => collection.set(integration.id, new Integration(this.client, integration, this)), - new Collection()) + new Collection()), ); } @@ -1035,7 +1050,7 @@ class Guild extends Base { this.client.actions.GuildChannelsPositionUpdate.handle({ guild_id: this.id, channels: updatedChannels, - }).guild + }).guild, ); } @@ -1069,7 +1084,7 @@ class Guild extends Base { this.client.actions.GuildRolePositionUpdate.handle({ guild_id: this.id, roles: rolePositions, - }).guild + }).guild, ); } @@ -1199,7 +1214,7 @@ class Guild extends Base { _sortedChannels(channel) { const category = channel.type === ChannelTypes.CATEGORY; return Util.discordSort(this.channels.filter(c => - c.type === channel.type && (category || c.parent === channel.parent) + c.type === channel.type && (category || c.parent === channel.parent), )); } }