GuildMemberManager

export class GuildMemberManager extends CachedManager<Snowflake, GuildMember, GuildMemberResolvable>
export class GuildMemberManager extends CachedManager<Snowflake, GuildMember, GuildMemberResolvable>
Manages API methods for GuildMembers 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
Readonly
The client user as a GuildMember of this guild
add(user, options):Promise<GuildMember | null>
Adds a user to the guild using OAuth2. This method requires the PermissionFlagsBits.CreateInstantInvite permission.
NameTypeOptionalDescription
userUserResolvableNoThe user to add to the guild
optionsAddGuildMemberOptions & { fetchWhenExisting: false }NoOptions for adding the user to the guild
addRole(options):Promise<GuildMember | User | Snowflake>
Adds a role to a member.
NameTypeOptionalDescription
optionsAddOrRemoveGuildMemberRoleOptionsNoOptions for adding the role
ban(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. Internally calls the GuildBanManager#create method.
Example
// Ban a user by id (or with a user/guild member object)
guild.members.ban('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.members.ban('84484653687267328')
.then(banInfo => console.log(`Banned ${banInfo.user?.tag ?? banInfo.tag ?? banInfo}`))
.catch(console.error);
NameTypeOptionalDescription
userUserResolvableNoThe user to ban
optionsBanOptionsYesOptions for the ban
bulkBan(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. Internally calls the GuildBanManager#bulkCreate method.
Example
// Bulk ban users by ids (or with user/guild member objects) and delete all their messages from the past 7 days
guild.members.bulkBan(['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.members.bulkBan(['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
optionsBulkBanOptionsYesThe options for bulk banning users
edit(user, options):Promise<GuildMember>
Edits a member of the guild. The user must be a member of the guild
NameTypeOptionalDescription
userUserResolvableNoThe member to edit
optionsGuildMemberEditOptionsNoThe options to provide
fetch(options):Promise<GuildMember>
Fetches member(s) from a guild.
Example
// Fetch all members from a guild
guild.members.fetch()
.then(console.log)
.catch(console.error);
// Fetch all members from a guild
guild.members.fetch()
.then(console.log)
.catch(console.error);
Example
// Fetch a single member
guild.members.fetch('66564597481480192')
.then(console.log)
.catch(console.error);
// Fetch a single member
guild.members.fetch('66564597481480192')
.then(console.log)
.catch(console.error);
Example
// Fetch a single member without checking cache
guild.members.fetch({ user, force: true })
.then(console.log)
.catch(console.error)
// Fetch a single member without checking cache
guild.members.fetch({ user, force: true })
.then(console.log)
.catch(console.error)
Example
// Fetch a single member without caching
guild.members.fetch({ user, cache: false })
.then(console.log)
.catch(console.error);
// Fetch a single member without caching
guild.members.fetch({ user, cache: false })
.then(console.log)
.catch(console.error);
Example
// Fetch by an array of users including their presences
guild.members.fetch({ user: ['66564597481480192', '191615925336670208'], withPresences: true })
.then(console.log)
.catch(console.error);
// Fetch by an array of users including their presences
guild.members.fetch({ user: ['66564597481480192', '191615925336670208'], withPresences: true })
.then(console.log)
.catch(console.error);
Example
// Fetch by query
guild.members.fetch({ query: 'hydra', limit: 1 })
.then(console.log)
.catch(console.error);
// Fetch by query
guild.members.fetch({ query: 'hydra', limit: 1 })
.then(console.log)
.catch(console.error);
NameTypeOptionalDescription
optionsUserResolvable | FetchMemberOptions | (FetchMembersOptions & { user: UserResolvable })NoOptions for fetching member(s). Omitting the parameter or providing undefined will fetch all members.
fetchMe(options?):Promise<GuildMember>
Fetches the client user as a GuildMember of the guild.
NameTypeOptionalDescription
optionsBaseFetchOptionsYesThe options for fetching the member
kick(user, reason?):Promise<GuildMember | User | Snowflake>
Kicks a user from the guild. The user must be a member of 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's id will be the result.
Example
// Kick a user by id (or with a user/guild member object)
guild.members.kick('84484653687267328')
.then(kickInfo => console.log(`Kicked ${kickInfo.user?.tag ?? kickInfo.tag ?? kickInfo}`))
.catch(console.error);
// Kick a user by id (or with a user/guild member object)
guild.members.kick('84484653687267328')
.then(kickInfo => console.log(`Kicked ${kickInfo.user?.tag ?? kickInfo.tag ?? kickInfo}`))
.catch(console.error);
NameTypeOptionalDescription
userUserResolvableNoThe member to kick
reasonstringYesReason for kicking
Lists up to 1000 members of the guild.
NameTypeOptionalDescription
optionsGuildListMembersOptionsYesOptions for listing members
prune(options):Promise<null>
Prunes members from the guild based on how long they have been inactive.
Returns
The number of members that were/will be kicked
Example
// See how many members will be pruned
guild.members.prune({ dry: true })
.then(pruned => console.log(`This will prune ${pruned} people!`))
.catch(console.error);
// See how many members will be pruned
guild.members.prune({ dry: true })
.then(pruned => console.log(`This will prune ${pruned} people!`))
.catch(console.error);
Example
// Actually prune the members
guild.members.prune({ days: 1, reason: 'too many people!' })
.then(pruned => console.log(`I just pruned ${pruned} people!`))
.catch(console.error);
// Actually prune the members
guild.members.prune({ days: 1, reason: 'too many people!' })
.then(pruned => console.log(`I just pruned ${pruned} people!`))
.catch(console.error);
Example
// Include members with a specified role
guild.members.prune({ days: 7, roles: ['657259391652855808'] })
.then(pruned => console.log(`I just pruned ${pruned} people!`))
.catch(console.error);
// Include members with a specified role
guild.members.prune({ days: 7, roles: ['657259391652855808'] })
.then(pruned => console.log(`I just pruned ${pruned} people!`))
.catch(console.error);
NameTypeOptionalDescription
optionsGuildPruneMembersOptions & { dry?: false; count: false }NoOptions for pruning
removeRole(options):Promise<GuildMember | User | Snowflake>
Removes a role from a member.
NameTypeOptionalDescription
optionsAddOrRemoveGuildMemberRoleOptionsNoOptions for removing the role
resolve(member):GuildMember | null
Resolves a GuildMemberResolvable to a object.
NameTypeOptionalDescription
memberGuildMemberResolvableNoThe user that is part of the guild
resolveId(member):Snowflake | null
Resolves a GuildMemberResolvable to a member id.
NameTypeOptionalDescription
memberGuildMemberResolvableNoThe user that is part of the guild
Searches for members in the guild based on a query.
NameTypeOptionalDescription
optionsGuildSearchMembersOptionsNoOptions for searching members
unban(user, reason?):Promise<User | null>
Unbans a user from the guild. Internally calls the remove method.
Returns
The user that was unbanned
Example
// Unban a user by id (or with a user/guild member object)
guild.members.unban('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.members.unban('84484653687267328')
.then(user => console.log(`Unbanned ${user.username} from ${guild.name}`))
.catch(console.error);
NameTypeOptionalDescription
userUserResolvableNoThe user to unban
reasonstringYesReason for unbanning user
valueOf():Collection<Key, Holds>