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

pub struct Member {
    pub deaf: bool,
    pub guild_id: GuildId,
    pub joined_at: Option<DateTime<FixedOffset>>,
    pub mute: bool,
    pub nick: Option<String>,
    pub roles: Vec<RoleId>,
    pub user: Arc<RwLock<User>>,
    // some fields omitted
}

Information about a member of a guild.

Fields

deaf: bool

Indicator of whether the member can hear in voice channels.

guild_id: GuildId

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

joined_at: Option<DateTime<FixedOffset>>

Timestamp representing the date when the member joined.

mute: bool

Indicator of whether the member can speak in voice channels.

nick: Option<String>

The member's nickname, if present.

Can't be longer than 32 characters.

roles: Vec<RoleId>

Vector of Ids of Roles given to the member.

user: Arc<RwLock<User>>

Attached User struct.

Implementations

impl Member[src]

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

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

Note: Requires the Manage Roles permission.

pub fn add_roles(
    &mut self,
    http: impl AsRef<Http>,
    role_ids: &[RoleId]
) -> Result<()>
[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.

pub fn ban<BO: BanOptions>(
    &self,
    http: impl AsRef<Http>,
    ban_options: &BO
) -> Result<()>
[src]

Ban the member from its guild, deleting the last X number of days' worth of messages.

Note: Requires the Ban Members permission.

Errors

Returns a ModelError::GuildNotFound if the guild could not be found.

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

Determines the member's colour.

pub fn default_channel(
    &self,
    cache: impl AsRef<CacheRwLock>
) -> Option<Arc<RwLock<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 fn edit<F: FnOnce(&mut EditMember) -> &mut EditMember>(
    &self,
    http: impl AsRef<Http>,
    f: F
) -> Result<()>
[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.

pub fn highest_role_info(
    &self,
    cache: impl AsRef<CacheRwLock>
) -> 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 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:

This example is not tested
// assuming a `member` has already been bound
match member.kick() {
    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.

pub 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:

This example is not tested
match member.kick(&ctx.http, "A Reason") {
    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

Same as kick

pub fn permissions(&self, cache: impl AsRef<CacheRwLock>) -> Result<Permissions>[src]

Returns the guild-level permissions for the member.

Examples

This example is not tested
// 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 fn remove_role<R: Into<RoleId>>(
    &mut self,
    http: impl AsRef<Http>,
    role_id: R
) -> Result<()>
[src]

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

Note: Requires the Manage Roles permission.

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

Removes one or multiple Roles from the member.

Note: Requires the Manage Roles permission.

pub fn roles(&self, cache: impl AsRef<CacheRwLock>) -> 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 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.

pub fn user_id(&self) -> UserId[src]

Retrieves the member's user ID.

This is a shortcut for accessing the user structfield, retrieving a reader guard, and then copying its ID.

Deadlocking

This function can deadlock while retrieving a read guard to the user object if your application infinitely holds a write lock elsewhere.

Trait Implementations

impl Clone for Member[src]

impl Debug for Member[src]

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

impl Display for Member[src]

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

Mentions the user so that they receive a notification.

Examples

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

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

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

Gets the Id of a Member.

impl From<Member> for UserId[src]

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

Gets the Id of a Member.

impl Mentionable for Member[src]

impl Serialize for Member[src]

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]

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

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

impl<T> CloneAny for T where
    T: Clone + Any
[src]

impl<T> DebugAny for T where
    T: Any + Debug
[src]

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

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

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

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

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.

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

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.

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.

impl<T> UnsafeAny for T where
    T: Any

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