GuildBanManager

export class GuildBanManager extends CachedManager<Snowflake, GuildBan, GuildBanResolvable>
export class GuildBanManager extends CachedManager<Snowflake, GuildBan, GuildBanResolvable>
Manages API methods for guild bans and stores their cache.
Readonly
cache:Collection<Key, Holds>
The cache of items for this manager.
Inherited from DataManager
Readonly
client:Client
The client that instantiated this Manager
Inherited from BaseManager
guild:Guild
The guild this Manager belongs to
Readonly
holds:Constructable<Holds>
The data structure belonging to this manager.
Inherited from DataManager
bulkCreate(users, options?):Promise<BulkBanResult>
Bulk ban users from a guild, and optionally delete previous messages sent by them.
Returns
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.
Example
// 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);
// 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);
NameTypeOptionalDescription
usersReadonlyCollection<Snowflake, UserResolvable> | readonly UserResolvable[]NoThe users to ban
optionsBanOptionsYesThe options for bulk banning users
create(user, options?):Promise<GuildMember | User | Snowflake>
Bans a user from the guild.
Returns
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.
Example
// 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);
// 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);
NameTypeOptionalDescription
userUserResolvableNoThe user to ban
optionsBanOptionsYesOptions for the ban
fetch(options):Promise<GuildBan>
Fetches ban(s) from Discord.
Example
// Fetch multiple bans from a guild
guild.bans.fetch()
.then(console.log)
.catch(console.error);
// Fetch multiple bans from a guild
guild.bans.fetch()
.then(console.log)
.catch(console.error);
Example
// Fetch a maximum of 5 bans from a guild without caching
guild.bans.fetch({ limit: 5, cache: false })
.then(console.log)
.catch(console.error);
// Fetch a maximum of 5 bans from a guild without caching
guild.bans.fetch({ limit: 5, cache: false })
.then(console.log)
.catch(console.error);
Example
// Fetch a single ban
guild.bans.fetch('351871113346809860')
.then(console.log)
.catch(console.error);
// Fetch a single ban
guild.bans.fetch('351871113346809860')
.then(console.log)
.catch(console.error);
Example
// Fetch a single ban without checking cache
guild.bans.fetch({ user, force: true })
.then(console.log)
.catch(console.error)
// Fetch a single ban without checking cache
guild.bans.fetch({ user, force: true })
.then(console.log)
.catch(console.error)
Example
// Fetch a single ban without caching
guild.bans.fetch({ user, cache: false })
.then(console.log)
.catch(console.error);
// Fetch a single ban without caching
guild.bans.fetch({ user, cache: false })
.then(console.log)
.catch(console.error);
NameTypeOptionalDescription
optionsUserResolvable | FetchBanOptionsNoOptions for fetching guild ban(s)
remove(user, reason?):Promise<User | null>
Unbans a user from the guild.
Example
// 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);
// 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);
NameTypeOptionalDescription
userUserResolvableNoThe user to unban
reasonstringYesReason for unbanning user
resolve(ban):GuildBan | null
Resolves a GuildBanResolvable to a GuildBan object.
NameTypeOptionalDescription
banGuildBanResolvableNoThe ban that is in the guild
resolveId(idOrInstance):Key
Resolves a data entry to an instance id.
Returns
NameTypeOptionalDescription
idOrInstanceKey | HoldsNoThe id or instance of something in this Manager
valueOf():Collection<Key, Holds>