mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
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:
@@ -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',
|
||||
|
||||
|
||||
@@ -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
1
typings/index.d.ts
vendored
@@ -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>>;
|
||||
|
||||
Reference in New Issue
Block a user