#[non_exhaustive]pub struct Role {
pub id: RoleId,
pub guild_id: GuildId,
pub colour: Colour,
pub hoist: bool,
pub managed: bool,
pub mentionable: bool,
pub name: String,
pub permissions: Permissions,
pub position: i64,
pub tags: RoleTags,
pub icon: Option<String>,
pub unicode_emoji: Option<String>,
}
Expand description
Information about a role within a guild. A role represents a set of permissions, and can be attached to one or multiple users. A role has various miscellaneous configurations, such as being assigned a colour. Roles are unique per guild and do not cross over to other guilds in any way, and can have channel-specific permission overrides in addition to guild-level permissions.
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.id: RoleId
The Id of the role. Can be used to calculate the role’s creation date.
guild_id: GuildId
The Id of the Guild the Role is in.
colour: Colour
utils
only.The colour of the role. This is an ergonomic representation of the inner value.
hoist: bool
Indicator of whether the role is pinned above lesser roles.
In the client, this causes Member
s in the role to be seen above
those in roles with a lower Self::position
.
managed: bool
Indicator of whether the role is managed by an integration service.
mentionable: bool
Indicator of whether the role can be mentioned, similar to mentioning a
specific member or @everyone
.
Only members of the role will be notified if a role is mentioned with
this set to true
.
name: String
The name of the role.
permissions: Permissions
A set of permissions that the role has been assigned.
See the permissions
module for more information.
position: i64
The role’s position in the position list. Roles are considered higher in hierarchy if their position is higher.
The @everyone
role is usually either -1
or 0
.
The tags this role has. It can be used to determine if this role is a special role in this guild
such as guild subscriber role, or if the role is linked to an Integration
or a bot.
icon: Option<String>
Role icon image hash.
role-icons/<role_id>/<hash>.png
- PNG, JPEG, WEBP
role-icons/<role_id>/a_<hash>.gif
- GIF, Animated WEBP
unicode_emoji: Option<String>
Role unicoded image.
Implementations
sourceimpl Role
impl Role
sourcepub async fn delete(&mut self, http: impl AsRef<Http>) -> Result<()>
Available on crate feature model
only.
pub async fn delete(&mut self, http: impl AsRef<Http>) -> Result<()>
model
only.Deletes the role.
Note Requires the Manage Roles permission.
Errors
Returns Error::Http
if the current user lacks permission to
delete this role.
sourcepub async fn edit(
&self,
http: impl AsRef<Http>,
f: impl FnOnce(&mut EditRole) -> &mut EditRole
) -> Result<Role>
Available on crate feature model
only.
pub async fn edit(
&self,
http: impl AsRef<Http>,
f: impl FnOnce(&mut EditRole) -> &mut EditRole
) -> Result<Role>
model
only.Edits a Role
, optionally setting its new fields.
Requires the Manage Roles permission.
Examples
Make a role hoisted:
// assuming a `role` has already been bound
role.edit(|r| r.hoist(true));
Errors
Returns Error::Http
if the current user does not
have permission to Manage Roles.
sourcepub fn has_permission(&self, permission: Permissions) -> bool
Available on crate feature model
only.
pub fn has_permission(&self, permission: Permissions) -> bool
model
only.Check that the role has the given permission.
sourcepub fn has_permissions(&self, permissions: Permissions, precise: bool) -> bool
Available on crate feature model
only.
pub fn has_permissions(&self, permissions: Permissions, precise: bool) -> bool
model
only.Checks whether the role has all of the given permissions.
The ‘precise’ argument is used to check if the role’s permissions are
precisely equivalent to the given permissions. If you need only check
that the role has at least the given permissions, pass false
.
Trait Implementations
sourceimpl ArgumentConvert for Role
impl ArgumentConvert for Role
Look up a Role
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 (case-insensitive)
type Err = RoleParseError
type Err = RoleParseError
utils
and client
only.The associated error which can be returned from parsing.
sourcefn convert<'life0, 'life1, 'async_trait>(
ctx: &'life0 Context,
guild_id: Option<GuildId>,
_channel_id: Option<ChannelId>,
s: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Err>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn convert<'life0, 'life1, 'async_trait>(
ctx: &'life0 Context,
guild_id: Option<GuildId>,
_channel_id: Option<ChannelId>,
s: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Err>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
utils
and client
only.Parses a string s
as a command parameter of this type.
sourceimpl<'de> Deserialize<'de> for Role
impl<'de> Deserialize<'de> for Role
sourcefn 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
sourceimpl FromStrAndCache for Role
Available on crate features cache
and model
and utils
only.
impl FromStrAndCache for Role
cache
and model
and utils
only.sourceimpl Mentionable for Role
impl Mentionable for Role
sourceimpl Ord for Role
impl Ord for Role
sourceimpl PartialOrd<Role> for Role
impl PartialOrd<Role> for Role
sourcefn partial_cmp(&self, other: &Role) -> Option<Ordering>
fn partial_cmp(&self, other: &Role) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for Role
Auto Trait Implementations
impl RefUnwindSafe for Role
impl Send for Role
impl Sync for Role
impl Unpin for Role
impl UnwindSafe for Role
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more