Struct skua::model::guild::Member

source ·
#[non_exhaustive]
pub struct Member {
Show 14 fields pub user: User, pub nick: Option<String>, pub avatar: Option<ImageHash>, pub roles: Vec<RoleId>, pub joined_at: Option<Timestamp>, pub premium_since: Option<Timestamp>, pub deaf: bool, pub mute: bool, pub flags: GuildMemberFlags, pub pending: bool, pub permissions: Option<Permissions>, pub communication_disabled_until: Option<Timestamp>, pub guild_id: GuildId, pub unusual_dm_activity_until: Option<Timestamp>,
}
Expand description

Information about a member of a guild.

Discord docs, extra fields.

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.
§user: User

Attached User struct.

§nick: Option<String>

The member’s nickname, if present.

Can’t be longer than 32 characters.

§avatar: Option<ImageHash>

The guild avatar hash

§roles: Vec<RoleId>

Vector of Ids of Roles given to the member.

§joined_at: Option<Timestamp>

Timestamp representing the date when the member joined.

§premium_since: Option<Timestamp>

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

§deaf: bool

Indicator of whether the member can hear in voice channels.

§mute: bool

Indicator of whether the member can speak in voice channels.

§flags: GuildMemberFlags

Guild member flags.

§pending: bool

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

§permissions: Option<Permissions>

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

This is only Some when returned in an Interaction object.

§communication_disabled_until: Option<Timestamp>

When the user’s timeout will expire and the user will be able to communicate in the guild again.

Will be None or a time in the past if the user is not timed out.

§guild_id: GuildId

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

§unusual_dm_activity_until: Option<Timestamp>

If the member is currently flagged for sending excessive DMs to non-friend server members in the last 24 hours.

Will be None or a time in the past if the user is not timed out.

Implementations§

source§

impl Member

source

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

Available on crate feature model only.

Adds a Role to the member.

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.

source

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

Available on crate feature model only.

Adds one or multiple Roles to the member.

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.

source

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

Available on crate feature model only.

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.

source

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

Available on crate feature model only.

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.

source

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

Available on crate features model and cache only.

Determines the member’s colour.

source

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

Available on crate features model and cache only.

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)

source

pub async fn disable_communication_until_datetime( &mut self, cache_http: impl CacheHttp, time: Timestamp ) -> Result<()>

Available on crate feature model only.

Times the user out until time.

Requires the Moderate Members permission.

Note: Moderate Members: crate::model::permission::Permissions::MODERATE_MEMBERS

§Errors

Returns Error::Http if the current user lacks permission or if time is greater than 28 days from the current time.

source

pub fn display_name(&self) -> &str

Available on crate feature model only.

Calculates the member’s display name.

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

source

pub fn distinct(&self) -> String

Available on crate feature model only.

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

source

pub async fn edit( &mut self, cache_http: impl CacheHttp, builder: EditMember<'_> ) -> Result<()>

Available on crate feature model only.

Edits the member in place with the given data.

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

§Examples

See GuildId::edit_member for details.

§Errors

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

source

pub async fn enable_communication( &mut self, cache_http: impl CacheHttp ) -> Result<()>

Available on crate feature model only.

Allow a user to communicate, removing their timeout, if there is one.

Note: Requires the Moderate Members permission.

§Errors

Returns Error::Http if the current user lacks permission.

source

pub fn highest_role_info( &self, cache: impl AsRef<Cache> ) -> Option<(RoleId, u16)>

Available on crate features model and cache only.

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.

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.

source

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

Available on crate feature model only.

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.

source

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

Available on crate feature model only.

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.

source

pub async fn move_to_voice_channel( &self, cache_http: impl CacheHttp, channel: impl Into<ChannelId> ) -> Result<Member>

Available on crate feature model only.

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.

source

pub async fn disconnect_from_voice( &self, cache_http: impl CacheHttp ) -> Result<Member>

Available on crate feature model only.

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.

source

pub fn permissions(&self, cache: impl AsRef<Cache>) -> Result<Permissions>

Available on crate features model and cache only.

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(&cache).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.

source

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

Available on crate feature model only.

Removes a Role from the member.

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.

source

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

Available on crate feature model only.

Removes one or multiple Roles from the member.

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.

source

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

Available on crate features model and cache only.

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.

source

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

Available on crate feature model only.

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.

source

pub fn avatar_url(&self) -> Option<String>

Available on crate feature model only.

Returns the formatted URL of the member’s per guild avatar, if one exists.

This will produce a WEBP image URL, or GIF if the member has a GIF avatar.

source

pub fn face(&self) -> String

Available on crate feature model only.

Retrieves the URL to the current member’s avatar, falling back to the user’s avatar, then default avatar if needed.

This will call Self::avatar_url first, and if that returns None, it then falls back to User::face().

Trait Implementations§

source§

impl ArgumentConvert for Member

Available on crate features client and utils only.

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.
source§

fn convert<'life0, 'async_trait>( ctx: impl 'async_trait + CacheHttp, guild_id: Option<GuildId>, _channel_id: Option<ChannelId>, s: &'life0 str ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Err>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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

impl Clone for Member

source§

fn clone(&self) -> Member

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Member

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Member

source§

fn default() -> Member

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Member

source§

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

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Member

source§

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

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>.

source§

impl<'a> From<&'a Member> for UserId

source§

fn from(member: &Member) -> UserId

Gets the Id of a Member.

source§

impl From<Member> for PartialMember

source§

fn from(member: Member) -> Self

Converts to this type from the input type.
source§

impl From<Member> for UserId

source§

fn from(member: Member) -> UserId

Gets the Id of a Member.

source§

impl From<PartialMember> for Member

source§

fn from(partial: PartialMember) -> Self

Converts to this type from the input type.
source§

impl Mentionable for Member

source§

fn mention(&self) -> Mention

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

impl Serialize for Member

source§

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

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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
source§

impl<T> CloneDebuggableStorage for T

source§

impl<T> CloneableStorage for T
where T: Any + Send + Sync + Clone,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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

§

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

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DebuggableStorage for T
where T: Any + Send + Sync + Debug,

source§

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