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
This commit is contained in:
Sugden
2020-01-24 14:29:53 +00:00
committed by SpaceEEC
parent 63293fe14d
commit c779fe3670
3 changed files with 17 additions and 0 deletions

View File

@@ -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',

View File

@@ -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<Collection<Snowflake, BanInfo>>}

1
typings/index.d.ts vendored
View File

@@ -733,6 +733,7 @@ declare module 'discord.js' {
public equals(guild: Guild): boolean;
public fetch(): Promise<Guild>;
public fetchAuditLogs(options?: GuildAuditLogsFetchOptions): Promise<GuildAuditLogs>;
public fetchBan(user: UserResolvable): Promise<{ user: User, reason: string }>;
public fetchBans(): Promise<Collection<Snowflake, { user: User, reason: string }>>;
public fetchEmbed(): Promise<GuildEmbedData>;
public fetchIntegrations(): Promise<Collection<string, Integration>>;