From c779fe3670b2279de8638de6f2e70e008b1b1804 Mon Sep 17 00:00:00 2001 From: Sugden <28943913+NotSugden@users.noreply.github.com> Date: Fri, 24 Jan 2020 14:29:53 +0000 Subject: [PATCH] feat(Guild): add fetchBan method (#3726) * Add error for not resolving ID to fetch ban * Add Guild#fetchBan * add missing ! * typings * lint fixes * add jsdoc description --- src/errors/Messages.js | 1 + src/structures/Guild.js | 15 +++++++++++++++ typings/index.d.ts | 1 + 3 files changed, 17 insertions(+) diff --git a/src/errors/Messages.js b/src/errors/Messages.js index ae42f73c5..db339ca2c 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 the ban.', PRUNE_DAYS_TYPE: 'Days must be a number', diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 6b22cd25b..3dd518d40 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 information on a banned user from this guild. + * @param {UserResolvable} user The User to fetch the ban info of + * @returns {BanInfo} + */ + 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>} diff --git a/typings/index.d.ts b/typings/index.d.ts index 457f86a62..4c5a5ae28 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -733,6 +733,7 @@ declare module 'discord.js' { public equals(guild: Guild): boolean; public fetch(): Promise; public fetchAuditLogs(options?: GuildAuditLogsFetchOptions): Promise; + public fetchBan(user: UserResolvable): Promise<{ user: User, reason: string }>; public fetchBans(): Promise>; public fetchEmbed(): Promise; public fetchIntegrations(): Promise>;