Preview environment

class GuildMemberManager

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
me : GuildMember | null

The client user as a GuildMember of this guild

add(
options: AddGuildMemberOptions & { fetchWhenExisting: false }
) : Promise<GuildMember | null>

Adds a user to the guild using OAuth2. This method requires the PermissionFlagsBits.CreateInstantInvite permission.

Adds a role to a member.

Bans a user from the guild.

Examples:
// 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.

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

Examples:
// 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.

Edits a member of the guild. The user must be a member of the guild

Fetches member(s) from a guild.

Examples:
// 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);

fetchMe() : Promise<GuildMember>

Fetches the client user as a GuildMember of the guild.

Kicks a user from the guild. The user must be a member of the guild

Examples:
// 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.

Lists up to 1000 members of the guild.

prune(
options: GuildPruneMembersOptions & { dry?: false; count: false }
) : Promise<null>

Prunes members from the guild based on how long they have been inactive.

Examples:
// 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

Removes a role from a member.

resolve() : GuildMember | null

Resolves a GuildMemberResolvable to a GuildMember object.

resolveId() : Snowflake | null

Resolves a GuildMemberResolvable to a member id.

Searches for members in the guild based on a query.

unban(
reason?: string
) : Promise<User | null>

Unbans a user from the guild. Internally calls the remove method.

Examples:
// 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

valueOf() : Collection<Key, Holds>

Inherited from: DataManager