Skip to content

GuildBanManager

classe · Source

Manages API methods for GuildBans and stores their cache.

Extends: CachedManager

Properties

guild

guild: Guild

The guild this Manager belongs to Source

cache

cache: Collection<Snowflake, GuildBan>

The cache of this Manager Source

_cache

readonly · private

_cache: Collection

The private cache of items for this manager. Source

holds

readonly · private

holds: function

The data structure belonging to this manager. Source

client

readonly

client: Client

The client that instantiated this Manager Source

Methods

resolve

resolve(ban: GuildBanResolvable): GuildBan

Resolves a GuildBanResolvable to a GuildBan object. Parameters

NameTypeDescription
banGuildBanResolvableThe ban that is in the guild

Returns: GuildBanSource

fetch

async

async fetch(options?: UserResolvable | FetchBanOptions | FetchBansOptions): Promise<(GuildBan|Collection<Snowflake, GuildBan>)>

Fetches ban(s) from Discord. Parameters

NameTypeDescription
options?UserResolvable | FetchBanOptions | FetchBansOptionsOptions for fetching guild ban(s)

Returns: Promise<(GuildBan\|Collection<Snowflake, GuildBan>)>

js
// Fetch multiple bans from a guild
guild.bans.fetch()
  .then(console.log)
  .catch(console.error);
js
// Fetch a maximum of 5 bans from a guild without caching
guild.bans.fetch({ limit: 5, cache: false })
  .then(console.log)
  .catch(console.error);
js
// Fetch a single ban
guild.bans.fetch('351871113346809860')
  .then(console.log)
  .catch(console.error);
js
// Fetch a single ban without checking cache
guild.bans.fetch({ user, force: true })
  .then(console.log)
  .catch(console.error)
js
// Fetch a single ban without caching
guild.bans.fetch({ user, cache: false })
  .then(console.log)
  .catch(console.error);

Source

create

async

async create(user: UserResolvable, options?: BanOptions): Promise<(GuildMember|User|Snowflake)>

Bans a user from the guild. Parameters

NameTypeDescription
userUserResolvableThe user to ban
options?BanOptionsOptions for the ban

Returns: Promise<(GuildMember\|User\|Snowflake)> — Result object will be resolved as specifically as possible. If the GuildMember cannot be resolved, the User will instead be attempted to be resolved. If that also cannot be resolved, the user id will be the result.

js
// Ban a user by id (or with a user/guild member object)
guild.bans.create('84484653687267328')
  .then(banInfo => console.log(`Banned ${banInfo.user?.tag ?? banInfo.tag ?? banInfo}`))
  .catch(console.error);

Source

remove

async

async remove(user: UserResolvable, reason?: string): Promise<?User>

Unbans a user from the guild. Parameters

NameTypeDescription
userUserResolvableThe user to unban
reason?stringReason for unbanning user

Returns: Promise<?User>

js
// Unban a user by id (or with a user/guild member object)
guild.bans.remove('84484653687267328')
  .then(user => console.log(`Unbanned ${user.username} from ${guild.name}`))
  .catch(console.error);

Source

bulkCreate

async · deprecated

async bulkCreate(users: Collection<Snowflake, UserResolvable> | Array<UserResolvable>, options?: BulkBanOptions): Promise<BulkBanResult>

Bulk ban users from a guild, and optionally delete previous messages sent by them. Parameters

NameTypeDescription
usersCollection<Snowflake, UserResolvable> | Array<UserResolvable>The users to ban
options?BulkBanOptionsThe options for bulk banning users

Returns: Promise<BulkBanResult> — Returns an object with bannedUsers key containing the IDs of the banned users and the key failedUsers with the IDs that could not be banned or were already banned.

js
// Bulk ban users by ids (or with user/guild member objects) and delete all their messages from the past 7 days
guild.bans.bulkCreate(['84484653687267328'], { deleteMessageSeconds: 7 * 24 * 60 * 60 })
  .then(result => {
    console.log(`Banned ${result.bannedUsers.length} users, failed to ban ${result.failedUsers.length} users.`)
  })
  .catch(console.error);

Source

resolveId

resolveId(idOrInstance: string | Object): Snowflake

Resolves a data entry to an instance id. Parameters

NameTypeDescription
idOrInstancestring | ObjectThe id or instance of something in this Manager

Returns: SnowflakeSource

Unofficial software. Not affiliated with or supported by Discord.