Class: GuildMemberManager

GuildMemberManager

Manages API methods for GuildMembers and stores their cache.

Constructor

new GuildMemberManager()

Source:

Extends

Members

cache :Collection.<Snowflake, GuildMember>

The cache of this Manager
Type:
Overrides:
Source:

cacheType :Collection

The type of Collection of the Manager
Type:
  • Collection
Overrides:
Source:

(readonly) client :Client

The client that instantiated this Manager
Type:
Overrides:
Source:

guild :Guild

The guild this manager belongs to
Type:
Source:

(private, readonly) holds :function

The data structure belonging to this manager
Type:
  • function
Overrides:
Source:

Methods

ban(user, optionsopt) → {Promise.<(GuildMember|User|Snowflake)>}

Bans a user from the guild.
Parameters:
Name Type Attributes Description
user UserResolvable The user to ban
options Object <optional>
Options for the ban
Properties
Name Type Attributes Default Description
days number <optional>
0 Number of days of messages to delete, must be between 0 and 7
reason string <optional>
Reason for banning
Source:
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.
Type
Promise.<(GuildMember|User|Snowflake)>
Example
// Ban a user by ID (or with a user/guild member object)
guild.members.ban('84484653687267328')
  .then(user => console.log(`Banned ${user.username || user.id || user} from ${guild.name}`))
  .catch(console.error);

fetch(optionsopt) → {Promise.<GuildMember>|Promise.<Collection.<Snowflake, GuildMember>>}

Fetches member(s) from Discord, even if they're offline.
Parameters:
Name Type Attributes Description
options UserResolvable | FetchMemberOptions | FetchMembersOptions <optional>
If a UserResolvable, the user to fetch. If undefined, fetches all members. If a query, it limits the results to users with similar usernames.
Source:
Returns:
Type
Promise.<GuildMember> | Promise.<Collection.<Snowflake, GuildMember>>
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);

prune(optionsopt) → {Promise.<(number|null)>}

Prunes members from the guild based on how long they have been inactive. It's recommended to set options.count to `false` for large guilds.
Parameters:
Name Type Attributes Description
options Object <optional>
Prune options
Properties
Name Type Attributes Default Description
days number <optional>
7 Number of days of inactivity required to kick
dry boolean <optional>
false Get number of users that will be kicked, without actually kicking them
count boolean <optional>
true Whether or not to return the number of users that have been kicked.
roles Array.<RoleResolvable> <optional>
[] Array of roles to bypass the "...and no roles" constraint when pruning
reason string <optional>
Reason for this prune
Source:
Returns:
The number of members that were/will be kicked
Type
Promise.<(number|null)>
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);

resolve(member) → {GuildMember}

Resolves a GuildMemberResolvable to a GuildMember object.
Parameters:
Name Type Description
member GuildMemberResolvable The user that is part of the guild
Overrides:
Source:
Returns:
Type
GuildMember

resolveID(member) → {Snowflake}

Resolves a GuildMemberResolvable to a member ID string.
Parameters:
Name Type Description
member GuildMemberResolvable The user that is part of the guild
Overrides:
Source:
Returns:
Type
Snowflake

unban(user, reasonopt) → {Promise.<User>}

Unbans a user from the guild.
Parameters:
Name Type Attributes Description
user UserResolvable The user to unban
reason string <optional>
Reason for unbanning user
Source:
Returns:
Type
Promise.<User>
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);