class GuildMemberManager
extends
CachedManager<Snowflake, GuildMember, GuildMemberResolvable>export class GuildMemberManager extends CachedManager<Snowflake, GuildMember, GuildMemberResolvable>
Manages API methods for GuildMembers and stores their cache.
readonlyCollection<Key, Holds> cache :
The cache of items for this manager.
Inherited from: DataManager
Guild guild :
The guild this manager belongs to
readonlyConstructable<Holds> holds :
The data structure belonging to this manager.
Inherited from: DataManager
readonlyGuildMember | null me :
The client user as a GuildMember of this guild
adduser: UserResolvableoptions: AddGuildMemberOptions & { fetchWhenExisting: false }) : Promise<GuildMember | null> (
Adds a user to the guild using OAuth2. This method requires the PermissionFlagsBits permission.
addRoleoptions: AddOrRemoveGuildMemberRoleOptions) : Promise<GuildMember | User | Snowflake> (
Adds a role to a member.
banuser: UserResolvableoptions?: BanOptions) : Promise<GuildMember | User | Snowflake> (
Bans a user from the guild.
// 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);
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.
bulkBanusers: ReadonlyCollection<Snowflake, UserResolvable> | readonly UserResolvable[]options?: BulkBanOptions) : Promise<BulkBanResult> (
Bulk ban users from a guild, and optionally delete previous messages sent by them.
// 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);
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.
edituser: UserResolvableoptions: GuildMemberEditOptions) : Promise<GuildMember> (
Edits a member of the guild. The user must be a member of the guild
fetchoptions: UserResolvable | FetchMemberOptions | (FetchMembersOptions & { user: UserResolvable })) : Promise<GuildMember> (
Fetches member(s) from a guild.
// Fetch all members from a guild
guild.members.fetch()
.then(console.log)
.catch(console.error);
// Fetch a single member
guild.members.fetch('66564597481480192')
.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)
// Fetch a single member without caching
guild.members.fetch({ user, cache: false })
.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);
// Fetch by query
guild.members.fetch({ query: 'hydra', limit: 1 })
.then(console.log)
.catch(console.error);
fetchMeoptions?: BaseFetchOptions) : Promise<GuildMember> (
Fetches the client user as a GuildMember of the guild.
kickuser: UserResolvablereason?: string) : Promise<GuildMember | User | Snowflake> (
Kicks a user from the guild. The user must be a member of the guild
// 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);
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.
listoptions?: GuildListMembersOptions) : Promise<Collection<Snowflake, GuildMember>> (
Lists up to 1000 members of the guild.
pruneoptions: GuildPruneMembersOptions & { dry?: false; count: false }) : Promise<null> (
Prunes members from the guild based on how long they have been inactive.
// See how many members will be pruned
guild.members.prune({ dry: true })
.then(pruned => console.log(`This will prune ${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);
// 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);
Returns: The number of members that were/will be kicked
removeRoleoptions: AddOrRemoveGuildMemberRoleOptions) : Promise<GuildMember | User | Snowflake> (
Removes a role from a member.
resolvemember: GuildMemberResolvable) : GuildMember | null (
Resolves a GuildMemberResolvable to a GuildMember object.
resolveIdmember: GuildMemberResolvable) : Snowflake | null (
Resolves a GuildMemberResolvable to a member id.
searchoptions: GuildSearchMembersOptions) : Promise<Collection<Snowflake, GuildMember>> (
Searches for members in the guild based on a query.
unbanuser: UserResolvablereason?: string) : Promise<User | null> (
Unbans a user from the guild. Internally calls the remove method.
// 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);
Returns: The user that was unbanned
valueOfCollection<Key, Holds> () :
Inherited from: DataManager