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>,
pub avatar: Option<String>,
pub communication_disabled_until: Option<DateTime<Utc>>,
}
Expand description
Information about a member of a guild.
Fields (Non-exhaustive)
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.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<Utc>>
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 Role
s given to the member.
user: User
Attached User struct.
pending: bool
Indicator that the member hasn’t accepted the rules of the guild yet.
Timestamp representing the date since the member is boosting the guild.
permissions: Option<Permissions>
The total permissions of the member in a channel, including overrides.
This is only Some
when returned in an Interaction
object.
avatar: Option<String>
The guild avatar hash
communication_disabled_until: Option<DateTime<Utc>>
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.
Implementations
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.
Adds one or multiple Role
s 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.
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.
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.
Determines the member’s colour.
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
)
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.
Calculates the member’s display name.
The nickname takes priority over the member’s username if it exists.
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,
pub async fn edit<F>(&self, http: impl AsRef<Http>, f: F) -> Result<Member> where
F: FnOnce(&mut EditMember) -> &mut EditMember,
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.
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.
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.
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.
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.
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.
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>
pub async fn permissions(
&self,
cache_http: impl CacheHttp + AsRef<Cache>
) -> Result<Permissions>
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.
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.
Removes one or multiple Role
s 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.
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.
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.
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.
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
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):
- Lookup by ID.
- Lookup by mention.
- Lookup by name#discrim.
- Lookup by name
- Lookup by nickname
type Err = MemberParseError
type Err = MemberParseError
The associated error which can be returned from parsing.
Parses a string s
as a command parameter of this type.
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl RefUnwindSafe for Member
impl UnwindSafe for Member
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more