Skip to main content

MemberManager

Struct MemberManager 

Source
pub struct MemberManager<'a, B: Backend> { /* private fields */ }
Expand description

The members of one guild. Returned by Context::members.

discord.js counterpart: GuildMemberManager (guild.members).

Implementations§

Source§

impl<'a, B: Backend> MemberManager<'a, B>

Source

pub const fn guild_id(self) -> GuildId

The guild these members belong to.

discord.js counterpart: GuildMemberManager#guild.

Source

pub fn cache(self) -> Option<GuildView<'a, UserId, CachedMember, B>>

The cached members of the guild, if the client has a cache.

discord.js counterpart: GuildMemberManager#cache.

Source

pub fn fetch( self, user_id: UserId, ) -> Fetch<Arc<CachedMember>, impl Future<Output = Result<Arc<CachedMember>, Error>> + Send + 'a>

A member: the cached one, or Get Guild Member, whose result is cached.

discord.js counterpart: GuildMemberManager#fetch(user).

§Errors

Returns the REST error if Discord was asked and the request failed (for example, the user is not a member).

Source

pub fn fetch_all(self) -> FetchMembers<'a, B>

Every member of the guild, through the gateway (D-270): sends Request Guild Members on the guild’s shard and gathers every chunk of the answer. Needs the privileged GUILD_MEMBERS intent. The members (and, with presences, their presences) are cached.

Await the returned request; it fails with GatewayRequestError if the guild’s shard does not run here, the answer does not complete in time (120 seconds by default) or Discord rate limits it.

discord.js counterpart: GuildMemberManager#fetch() (no options).

§Examples
let members = ctx.members(guild_id).fetch_all().await?;
println!("{} members", members.len());
Source

pub fn fetch_by_query(self, query: impl Into<String>) -> FetchMembers<'a, B>

The members whose username or nickname starts with query, through the gateway (at most limit, 100 by default), like fetch_all.

discord.js counterpart: GuildMemberManager#fetch({ query, limit }).

Source

pub fn fetch_many( self, user_ids: impl IntoIterator<Item = UserId>, ) -> FetchMembers<'a, B>

The members with these user IDs, through the gateway, like fetch_all; IDs that are not members are left out. Discord takes 100 IDs per request, so more are asked in several requests, one after another.

discord.js counterpart: GuildMemberManager#fetch({ user: [ids] }).

Source

pub async fn list( self, query: &ListGuildMembers, ) -> Result<Collection<UserId, Arc<CachedMember>>, Error>

A page of members, sorted by user ID (List Guild Members; needs the GUILD_MEMBERS intent). The members are cached.

discord.js counterpart: GuildMemberManager#list.

§Errors

Returns the REST error if the request failed.

Source

pub async fn edit( self, user_id: UserId, body: &ModifyGuildMember, reason: Option<&str>, ) -> Result<Arc<CachedMember>, Error>

Edits a member (Modify Guild Member); the result is cached.

discord.js counterpart: GuildMemberManager#edit.

§Errors

Returns the REST error if the request failed.

Source

pub async fn timeout( self, user_id: UserId, until: Option<Timestamp>, reason: Option<&str>, ) -> Result<Arc<CachedMember>, Error>

Times a member out until until (at most 28 days ahead), or ends their timeout with None.

discord.js counterpart: GuildMember#timeout / GuildMember#disableCommunicationUntil.

§Errors

Returns the REST error if the request failed (it needs MODERATE_MEMBERS).

Source

pub async fn set_nickname( self, user_id: UserId, nickname: Option<&str>, reason: Option<&str>, ) -> Result<Arc<CachedMember>, Error>

Sets a member’s nickname, or removes it with None.

discord.js counterpart: GuildMember#setNickname.

§Errors

Returns the REST error if the request failed (it needs MANAGE_NICKNAMES).

Source

pub async fn add_role( self, user_id: UserId, role_id: RoleId, reason: Option<&str>, ) -> Result<(), Error>

Gives a member a role (Add Guild Member Role).

discord.js counterpart: GuildMemberRoleManager#add.

§Errors

Returns the REST error if the request failed (it needs MANAGE_ROLES, and the role must be below the bot’s highest role).

Source

pub async fn remove_role( self, user_id: UserId, role_id: RoleId, reason: Option<&str>, ) -> Result<(), Error>

Takes a role from a member (Remove Guild Member Role).

discord.js counterpart: GuildMemberRoleManager#remove.

§Errors

Returns the REST error if the request failed.

Source

pub async fn kick( self, user_id: UserId, reason: Option<&str>, ) -> Result<(), Error>

Kicks a member (Remove Guild Member).

discord.js counterpart: GuildMemberManager#kick.

§Errors

Returns the REST error if the request failed (it needs KICK_MEMBERS).

Source

pub async fn ban( self, user_id: UserId, body: &CreateGuildBan, reason: Option<&str>, ) -> Result<(), Error>

Bans a user, member or not (the same as BanManager::create).

discord.js counterpart: GuildMemberManager#ban.

§Errors

Returns the REST error if the request failed (it needs BAN_MEMBERS).

Source

pub async fn unban( self, user_id: UserId, reason: Option<&str>, ) -> Result<(), Error>

Lifts a user’s ban (the same as BanManager::remove).

discord.js counterpart: GuildMemberManager#unban.

§Errors

Returns the REST error if the request failed (for example, the user is not banned).

Source

pub async fn search( self, query: &SearchGuildMembers, ) -> Result<Collection<UserId, Arc<CachedMember>>, Error>

Members whose username or nickname starts with a query (Search Guild Members); the members are cached.

discord.js counterpart: GuildMemberManager#search.

§Errors

Returns the REST error if the request failed.

Source

pub async fn edit_me( self, body: &ModifyCurrentMember, reason: Option<&str>, ) -> Result<Arc<CachedMember>, Error>

Edits the bot’s own membership: its nickname and guild profile (Modify Current Member); the result is cached.

discord.js counterpart: GuildMemberManager#editMe.

§Errors

Returns the REST error if the request failed (it needs CHANGE_NICKNAME for the nickname).

Source

pub async fn prune_count(self, query: &GetGuildPruneCount) -> Result<u32, Error>

How many members a prune would kick (Get Guild Prune Count).

discord.js counterpart: GuildMemberManager#prune with dry: true.

§Errors

Returns the REST error if the request failed (it needs MANAGE_GUILD and KICK_MEMBERS).

Source

pub async fn prune( self, body: &BeginGuildPrune, reason: Option<&str>, ) -> Result<Option<u32>, Error>

Kicks inactive members (Begin Guild Prune), returning how many were kicked unless compute_prune_count was false.

discord.js counterpart: GuildMemberManager#prune.

§Errors

Returns the REST error if the request failed (it needs MANAGE_GUILD and KICK_MEMBERS).

Trait Implementations§

Source§

impl<B: Backend> Clone for MemberManager<'_, B>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B: Backend> Copy for MemberManager<'_, B>

Source§

impl<'a, B: Debug + Backend> Debug for MemberManager<'a, B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, B> !RefUnwindSafe for MemberManager<'a, B>

§

impl<'a, B> !UnwindSafe for MemberManager<'a, B>

§

impl<'a, B> Freeze for MemberManager<'a, B>

§

impl<'a, B> Send for MemberManager<'a, B>

§

impl<'a, B> Sync for MemberManager<'a, B>

§

impl<'a, B> Unpin for MemberManager<'a, B>

§

impl<'a, B> UnsafeUnpin for MemberManager<'a, B>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Classify for T

§

type Classified = T

§

fn classify(self) -> T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Declassify for T

§

type Declassified = T

§

fn declassify(self) -> T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more