Struct serenity::model::guild::Member[][src]

#[non_exhaustive]
pub struct Member { pub deaf: bool, pub guild_id: GuildId, pub joined_at: Option<DateTime<Utc>>, pub mute: bool, pub nick: Option<String>, pub roles: Vec<RoleId>, pub user: User, pub pending: bool, pub premium_since: Option<DateTime<Utc>>, pub permissions: Option<Permissions>, }
Expand description

Information about a member of a guild.

Fields (Non-exhaustive)

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct {{ .. }} syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
deaf: bool
Expand description

Indicator of whether the member can hear in voice channels.

guild_id: GuildId
Expand description

The unique Id of the guild that the member is a part of.

joined_at: Option<DateTime<Utc>>
Expand description

Timestamp representing the date when the member joined.

mute: bool
Expand description

Indicator of whether the member can speak in voice channels.

nick: Option<String>
Expand description

The member’s nickname, if present.

Can’t be longer than 32 characters.

roles: Vec<RoleId>
Expand description

Vector of Ids of Roles given to the member.

user: User
Expand description

Attached User struct.

pending: bool
Expand description

Indicator that the member hasn’t accepted the rules of the guild yet.

premium_since: Option<DateTime<Utc>>
Expand description

Timestamp representing the date since the member is boosting the guild.

permissions: Option<Permissions>
This is supported on crate feature unstable_discord_api only.
Expand description

The total permissions of the member in a channel, including overrides.

This is only Some when returned in an Interaction object.

Implementations

impl Member[src]

pub async fn add_role(
    &mut self,
    http: impl AsRef<Http>,
    role_id: impl Into<RoleId>
) -> Result<()>
[src]

Adds a Role to the member, editing its roles in-place if the request was successful.

Note: Requires the Manage Roles permission.

Errors

Returns Error::Http if the current user lacks permission, or if a role with the given Id does not exist.

pub async fn add_roles(
    &mut self,
    http: impl AsRef<Http>,
    role_ids: &[RoleId]
) -> Result<Vec<RoleId>>
[src]

Adds one or multiple Roles to the member, editing its roles in-place if the request was successful.

Note: Requires the Manage Roles permission.

Errors

Returns Error::Http if the current user lacks permission, or if a role with a given Id does not exist.

pub async fn ban(&self, http: impl AsRef<Http>, dmd: u8) -> Result<()>[src]

Ban a User from the guild, deleting a number of days’ worth of messages (dmd) between the range 0 and 7.

Note: Requires the Ban Members permission.

Errors

Returns a ModelError::DeleteMessageDaysAmount if the dmd is greater than 7. Can also return Error::Http if the current user lacks permission to ban this member.

pub async fn ban_with_reason(
    &self,
    http: impl AsRef<Http>,
    dmd: u8,
    reason: impl AsRef<str>
) -> Result<()>
[src]

Ban the member from the guild with a reason. Refer to Self::ban to further documentation.

Errors

In addition to the errors Self::ban may return, can also return Error::ExceededLimit if the length of the reason is greater than 512.

pub async fn colour(&self, cache: impl AsRef<Cache>) -> Option<Colour>[src]

Determines the member’s colour.

pub async fn default_channel(
    &self,
    cache: impl AsRef<Cache>
) -> Option<GuildChannel>
[src]

Returns the “default channel” of the guild for the member. (This returns the first channel that can be read by the member, if there isn’t one returns None)

pub fn display_name(&self) -> Cow<'_, String>[src]

Calculates the member’s display name.

The nickname takes priority over the member’s username if it exists.

pub fn distinct(&self) -> String[src]

Returns the DiscordTag of a Member, taking possible nickname into account.

pub async fn edit<F>(&self, http: impl AsRef<Http>, f: F) -> Result<Member> where
    F: FnOnce(&mut EditMember) -> &mut EditMember
[src]

Edits the member with the given data. See Guild::edit_member for more information.

See EditMember for the permission(s) required for separate builder methods, as well as usage of this.

Errors

Returns Error::Http if the current user lacks necessary permissions.

pub async fn highest_role_info(
    &self,
    cache: impl AsRef<Cache>
) -> Option<(RoleId, i64)>
[src]

Retrieves the ID and position of the member’s highest role in the hierarchy, if they have one.

This may return None if:

  • the user has roles, but they are not present in the cache for cache inconsistency reasons
  • you already have a write lock to the member’s guild

The “highest role in hierarchy” is defined as the role with the highest position. If two or more roles have the same highest position, then the role with the lowest ID is the highest.

pub async fn kick(&self, cache_http: impl CacheHttp) -> Result<()>[src]

Kick the member from the guild.

Note: Requires the Kick Members permission.

Examples

Kick a member from its guild:

// assuming a `member` has already been bound
match member.kick().await {
    Ok(()) => println!("Successfully kicked member"),
    Err(Error::Model(ModelError::GuildNotFound)) => {
        println!("Couldn't determine guild of member");
    },
    Err(Error::Model(ModelError::InvalidPermissions(missing_perms))) => {
        println!("Didn't have permissions; missing: {:?}", missing_perms);
    },
    _ => {},
}

Errors

Returns a ModelError::GuildNotFound if the Id of the member’s guild could not be determined.

If the cache is enabled, returns a ModelError::InvalidPermissions if the current user does not have permission to perform the kick.

Otherwise will return Error::Http if the current user lacks permission.

pub async fn kick_with_reason(
    &self,
    cache_http: impl CacheHttp,
    reason: &str
) -> Result<()>
[src]

Kicks the member from the guild, with a reason.

Note: Requires the Kick Members permission.

Examples

Kicks a member from it’s guild, with an optional reason:

match member.kick(&ctx.http, "A Reason").await {
    Ok(()) => println!("Successfully kicked member"),
    Err(Error::Model(ModelError::GuildNotFound)) => {
        println!("Couldn't determine guild of member");
    },
    Err(Error::Model(ModelError::InvalidPermissions(missing_perms))) => {
        println!("Didn't have permissions; missing: {:?}", missing_perms);
    },
    _ => {},
}

Errors

In addition to the reasons Self::kick may return an error, can also return an error if the given reason is too long.

pub async fn move_to_voice_channel(
    &self,
    http: impl AsRef<Http>,
    channel: impl Into<ChannelId>
) -> Result<Member>
[src]

Moves the member to a voice channel.

Requires the Move Members permission.

Errors

Returns Error::Http if the member is not currently in a voice channel, or if the current user lacks permission.

pub async fn disconnect_from_voice(
    &self,
    http: impl AsRef<Http>
) -> Result<Member>
[src]

Disconnects the member from their voice channel if any.

Requires the Move Members permission.

Errors

Returns Error::Http if the member is not currently in a voice channel, or if the current user lacks permission.

pub async fn permissions(
    &self,
    cache_http: impl CacheHttp + AsRef<Cache>
) -> Result<Permissions>
[src]

Returns the guild-level permissions for the member.

Examples

// assuming there's a `member` variable gotten from anything.
println!("The permission bits for the member are: {}",
member.permissions().expect("permissions").bits);

Errors

Returns a ModelError::GuildNotFound if the guild the member’s in could not be found in the cache.

And/or returns ModelError::ItemMissing if the “default channel” of the guild is not found.

pub async fn remove_role(
    &mut self,
    http: impl AsRef<Http>,
    role_id: impl Into<RoleId>
) -> Result<()>
[src]

Removes a Role from the member, editing its roles in-place if the request was successful.

Note: Requires the Manage Roles permission.

Errors

Returns Error::Http if a role with the given Id does not exist, or if the current user lacks permission.

pub async fn remove_roles(
    &mut self,
    http: impl AsRef<Http>,
    role_ids: &[RoleId]
) -> Result<Vec<RoleId>>
[src]

Removes one or multiple Roles from the member. Returns the member’s new roles.

Note: Requires the Manage Roles permission.

Errors

Returns Error::Http if a role with a given Id does not exist, or if the current user lacks permission.

pub async fn roles(&self, cache: impl AsRef<Cache>) -> Option<Vec<Role>>[src]

Retrieves the full role data for the user’s roles.

This is shorthand for manually searching through the Cache.

If role data can not be found for the member, then None is returned.

pub async fn unban(&self, http: impl AsRef<Http>) -> Result<()>[src]

Unbans the User from the guild.

Note: Requires the Ban Members permission.

Errors

If the cache is enabled, returns a ModelError::InvalidPermissions if the current user does not have permission to perform bans.

Trait Implementations

impl Clone for Member[src]

fn clone(&self) -> Member[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Member[src]

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

Formats the value using the given formatter. Read more

impl<'de> Deserialize<'de> for Member[src]

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
    __D: Deserializer<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl Display for Member[src]

fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult[src]

Mentions the user so that they receive a notification.

Examples

// assumes a `member` has already been bound
println!("{} is a member!", member);

This is in the format of <@USER_ID>.

impl From<&'_ Member> for Mention[src]

fn from(value: &Member) -> Self[src]

Performs the conversion.

impl<'a> From<&'a Member> for UserId[src]

fn from(member: &Member) -> UserId[src]

Gets the Id of a Member.

impl From<Member> for UserId[src]

fn from(member: Member) -> UserId[src]

Gets the Id of a Member.

impl Mentionable for Member[src]

fn mention(&self) -> Mention[src]

Creates a Mention that will be able to notify or create a link to the item. Read more

impl Parse for Member[src]

Look up a guild member by a string case-insensitively.

Requires the cache feature to be enabled.

The lookup strategy is as follows (in order):

  1. Lookup by ID.
  2. Lookup by mention.
  3. Lookup by name#discrim
  4. Lookup by name
  5. Lookup by nickname

type Err = MemberParseError

The associated error which can be returned from parsing.

fn parse<'life0, 'life1, 'life2, 'async_trait>(
    ctx: &'life0 Context,
    msg: &'life1 Message,
    s: &'life2 str
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Err>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

Parses a string s as a command parameter of this type.

impl Serialize for Member[src]

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
    __S: Serializer
[src]

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

impl RefUnwindSafe for Member

impl Send for Member

impl Sync for Member

impl Unpin for Member

impl UnwindSafe for Member

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

fn instrument(self, span: Span) -> Instrumented<Self>[src]

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

fn in_current_span(self) -> Instrumented<Self>[src]

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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

pub fn vzip(self) -> V

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]