GuildMemberManager
classe · Source
Manages API methods for GuildMembers and stores their cache.
Extends: CachedManager
Properties
guild
The guild this manager belongs to Source
cache
The cache of this Manager Source
me
The client user as a GuildMember of this guild Source
_cache
The private cache of items for this manager. Source
holds
The data structure belonging to this manager. Source
client
The client that instantiated this Manager Source
Methods
resolve
Resolves a GuildMemberResolvable to a GuildMember object. Parameters
| Name | Type | Description |
|---|---|---|
member | GuildMemberResolvable | The user that is part of the guild |
Returns: GuildMemberSource
resolveId
Resolves a GuildMemberResolvable to a member id. Parameters
| Name | Type | Description |
|---|---|---|
member | GuildMemberResolvable | The user that is part of the guild |
Returns: SnowflakeSource
add
Adds a user to the guild using OAuth2. Requires the CREATE_INSTANT_INVITE permission. Parameters
| Name | Type | Description |
|---|---|---|
user | UserResolvable | The user to add to the guild |
options | AddGuildMemberOptions | Options for adding the user to the guild |
Returns: Promise<(GuildMember\|null)>Source
fetch
Fetches member(s) from Discord, even if they're offline. Parameters
| Name | Type | Description |
|---|---|---|
options? | UserResolvable | FetchMemberOptions | FetchMembersOptions | If a UserResolvable, the user to fetch. If undefined, fetches all members. If a query, it limits the results to users with similar usernames. |
Returns: Promise<(GuildMember\|Collection<Snowflake, GuildMember>)>
// 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
Fetches the client user as a GuildMember of the guild. Parameters
| Name | Type | Description |
|---|---|---|
options? | BaseFetchOptions | The options for fetching the member |
Returns: Promise<GuildMember>Source
search
Searches for members in the guild based on a query. Parameters
| Name | Type | Description |
|---|---|---|
options | GuildSearchMembersOptions | Options for searching members |
Returns: Promise<Collection<Snowflake, GuildMember>>Source
edit
Edits a member of the guild. The user must be a member of the guild Parameters
| Name | Type | Description |
|---|---|---|
user | UserResolvable | The member to edit |
data | GuildMemberEditData | The data to edit the member with |
reason? | string | Reason for editing this user |
Returns: Promise<GuildMember>Source
prune
Prunes members from the guild based on how long they have been inactive. Parameters
| Name | Type | Description |
|---|---|---|
options? | GuildPruneMembersOptions | Options for pruning |
Returns: Promise<(number\|null)> — The number of members that were/will be kicked
// 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);kick
Kicks a user from the guild. The user must be a member of the guild Parameters
| Name | Type | Description |
|---|---|---|
user | UserResolvable | The member to kick |
reason? | string | Reason for kicking |
Returns: Promise<(GuildMember\|User\|Snowflake)> — 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.
// 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);ban
Bans a user from the guild. Parameters
| Name | Type | Description |
|---|---|---|
user | UserResolvable | The user to ban |
options? | BanOptions | Options for the ban |
Returns: Promise<(GuildMember\|User\|Snowflake)> — 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.
// 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);unban
Unbans a user from the guild. Internally calls the GuildBanManager#remove method. Parameters
| Name | Type | Description |
|---|---|---|
user | UserResolvable | The user to unban |
reason? | string | Reason for unbanning user |
Returns: Promise<?User> — The user that was unbanned
// 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);addRole
Adds a role to a member. Parameters
| Name | Type | Description |
|---|---|---|
user | GuildMemberResolvable | The user to add the role from |
role | RoleResolvable | The role to add |
reason? | string | Reason for adding the role |
Returns: Promise<(GuildMember\|User\|Snowflake)>Source
removeRole
Removes a role from a member. Parameters
| Name | Type | Description |
|---|---|---|
user | UserResolvable | The user to remove the role from |
role | RoleResolvable | The role to remove |
reason? | string | Reason for removing the role |
Returns: Promise<(GuildMember\|User\|Snowflake)>Source
fetchByMemberSafety
Experimental method to fetch members from the guild. Lists up to 10000 members of the guild. Parameters
| Name | Type | Description |
|---|---|---|
timeout? | number | Timeout for receipt of members in ms Default: 15_000. |
Returns: Promise<Collection<Snowflake, GuildMember>>Source
bulkBan
Bulk ban users from a guild, and optionally delete previous messages sent by them. Parameters
| Name | Type | Description |
|---|---|---|
users | Collection<Snowflake, UserResolvable> | Array<UserResolvable> | The users to ban |
options? | BulkBanOptions | The options for bulk banning users |
Returns: Promise<BulkBanResult> — 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.
// 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);