pub struct PermissionCalculator<'a> { /* private fields */ }
permission-calculator
only.Expand description
Calculate the permissions of a member.
Using the member calculator you can calculate the member’s permissions in the root-level of a guild or in a given channel.
Implementations§
Source§impl<'a> PermissionCalculator<'a>
impl<'a> PermissionCalculator<'a>
Sourcepub const fn new(
guild_id: Id<GuildMarker>,
user_id: Id<UserMarker>,
everyone_role: Permissions,
member_roles: &'a [(Id<RoleMarker>, Permissions)],
) -> Self
pub const fn new( guild_id: Id<GuildMarker>, user_id: Id<UserMarker>, everyone_role: Permissions, member_roles: &'a [(Id<RoleMarker>, Permissions)], ) -> Self
Create a calculator to calculate the permissions of a member.
everyone_role
is the permissions of the @everyone
role on a
guild-level; the permissions may be empty. The @everyone
role’s ID is
the same as that of the guild_id
.
The provided member’s roles should not contain the @everyone
role.
Sourcepub const fn owner_id(self, owner_id: Id<UserMarker>) -> Self
pub const fn owner_id(self, owner_id: Id<UserMarker>) -> Self
Configure the ID of the owner of the guild.
This should be used if you don’t want to manually take the user ID and owner ID in account beforehand.
If the member’s ID is the same as the owner’s ID then permission
calculating methods such as root
will return all permissions
enabled.
Sourcepub const fn in_channel(
self,
channel_type: ChannelType,
channel_overwrites: &[PermissionOverwrite],
) -> Permissions
pub const fn in_channel( self, channel_type: ChannelType, channel_overwrites: &[PermissionOverwrite], ) -> Permissions
Calculate the permissions of the member in a channel, taking into account a combination of the guild-level permissions and channel-level permissions.
Note that this method will not return guild-level permissions such
as Manage Guild Expressions; if you need the guild-level permissions
use root
.
§Conditional exclusions
When the member doesn’t have the “View Channel” permission then an empty permission set will be returned. This will happen in the following circumstances:
- When the permission is denied on the role level and isn’t enabled on a role or member permission overwrite;
- When the permission is denied on a role permission overwrite but isn’t enabled on a member permission overwrite; or
- When permission isn’t enabled on a guild level and isn’t enabled via a permission overwrite.
When the Send Messages permission is denied and is not similarly enabled like above then the Attach Files, Embed Links, Mention Everyone, and Send TTS Messages permissions will not be present in the returned permission set.
§Channel-based exclusions
Permissions are removed based on the type of a channel. For example, when calculating the permissions of a voice channel we can know that if Send Messages is granted on a guild-level to everyone then it is omitted from the permissions for a specific channel.
§Stage Channels
When the given channel type is a guild stage channel then the following permissions will be removed:
- Add Reactions
- Attach Files
- Deafen Members
- Embed Links
- Manage Webhooks
- Mention Everyone
- Priority Speaker
- Read Message History
- Send Messages
- Send TTS Messages
- Stream
- Speak
- Use External Emojis
- Use Slash Commands
- Use VAD
§Text Channels
When the given channel type is a guild text channel then the following permissions will be removed:
- Connect
- Deafen Members
- Move Members
- Mute Members
- Priority Speaker
- Request To Speak
- Speak
- Stream
- Use VAD
§Voice Channels
When the given channel type is a guild voice channel then the following permissions will be removed:
- Add Reactions
- Attach Files
- Embed Links
- Manage Messages
- Manage Webhooks
- Mention Everyone
- Read Message History
- Request To Speak
- Send Messages
- Send TTS Messages
- Use External Emojis
- Use Slash Commands
§Guild-based exclusions
The following guild-level permissions will always be removed:
- Administrator
- Ban Members
- Change Nickname
- Kick Members
- Manage Guild Expressions
- Manage Guild
- Manage Nicknames
- View Audit Log
- View Guild Insights
If you need to know a member’s guild-level permissions - such as whether
they have the View Audit Log permission - use root
instead.
§Examples
See the crate-level documentation for an example.
Trait Implementations§
Source§impl<'a> Clone for PermissionCalculator<'a>
impl<'a> Clone for PermissionCalculator<'a>
Source§fn clone(&self) -> PermissionCalculator<'a>
fn clone(&self) -> PermissionCalculator<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more