pub trait MemberExt: Member {
// Provided methods
fn edit<B: Backend>(
&self,
ctx: &Context<B>,
body: &ModifyGuildMember,
reason: Option<&str>,
) -> impl Future<Output = Result<Arc<CachedMember>, Error>> + Send { ... }
fn timeout<B: Backend>(
&self,
ctx: &Context<B>,
until: Option<Timestamp>,
reason: Option<&str>,
) -> impl Future<Output = Result<Arc<CachedMember>, Error>> + Send { ... }
fn set_nickname<B: Backend>(
&self,
ctx: &Context<B>,
nickname: Option<&str>,
reason: Option<&str>,
) -> impl Future<Output = Result<Arc<CachedMember>, Error>> + Send { ... }
fn add_role<B: Backend>(
&self,
ctx: &Context<B>,
role_id: RoleId,
reason: Option<&str>,
) -> impl Future<Output = Result<(), Error>> + Send { ... }
fn remove_role<B: Backend>(
&self,
ctx: &Context<B>,
role_id: RoleId,
reason: Option<&str>,
) -> impl Future<Output = Result<(), Error>> + Send { ... }
fn kick<B: Backend>(
&self,
ctx: &Context<B>,
reason: Option<&str>,
) -> impl Future<Output = Result<(), Error>> + Send { ... }
fn ban<B: Backend>(
&self,
ctx: &Context<B>,
body: &CreateGuildBan,
reason: Option<&str>,
) -> impl Future<Output = Result<(), Error>> + Send { ... }
fn permissions<B: Backend>(&self, ctx: &Context<B>) -> Option<Permissions> { ... }
fn permissions_in<B: Backend>(
&self,
ctx: &Context<B>,
channel_id: ChannelId,
) -> Option<Permissions> { ... }
}Expand description
Actions on a guild member: CachedMember, or the payload of
Events::GuildMemberAdd or
Events::GuildMemberUpdate.
This trait is sealed.
discord.js counterpart: the methods of GuildMember.
§Examples
const NEWCOMER: RoleId = RoleId::new(1_300_000_000_000_000_000);
client.on(Events::GuildMemberAdd, |ctx, member| async move {
member.add_role(&ctx, NEWCOMER, Some("new member")).await?;
Ok(())
});Provided Methods§
Sourcefn edit<B: Backend>(
&self,
ctx: &Context<B>,
body: &ModifyGuildMember,
reason: Option<&str>,
) -> impl Future<Output = Result<Arc<CachedMember>, Error>> + Send
fn edit<B: Backend>( &self, ctx: &Context<B>, body: &ModifyGuildMember, reason: Option<&str>, ) -> impl Future<Output = Result<Arc<CachedMember>, Error>> + Send
Edits this member (MemberManager::edit).
discord.js counterpart: GuildMember#edit.
§Errors
Returns the REST error if the request failed.
Sourcefn timeout<B: Backend>(
&self,
ctx: &Context<B>,
until: Option<Timestamp>,
reason: Option<&str>,
) -> impl Future<Output = Result<Arc<CachedMember>, Error>> + Send
fn timeout<B: Backend>( &self, ctx: &Context<B>, until: Option<Timestamp>, reason: Option<&str>, ) -> impl Future<Output = Result<Arc<CachedMember>, Error>> + Send
Times this member out until until, or ends the timeout with None
(MemberManager::timeout).
discord.js counterpart: GuildMember#timeout.
§Errors
Returns the REST error if the request failed.
Sourcefn set_nickname<B: Backend>(
&self,
ctx: &Context<B>,
nickname: Option<&str>,
reason: Option<&str>,
) -> impl Future<Output = Result<Arc<CachedMember>, Error>> + Send
fn set_nickname<B: Backend>( &self, ctx: &Context<B>, nickname: Option<&str>, reason: Option<&str>, ) -> impl Future<Output = Result<Arc<CachedMember>, Error>> + Send
Sets this member’s nickname, or removes it with None
(MemberManager::set_nickname).
discord.js counterpart: GuildMember#setNickname.
§Errors
Returns the REST error if the request failed.
Sourcefn add_role<B: Backend>(
&self,
ctx: &Context<B>,
role_id: RoleId,
reason: Option<&str>,
) -> impl Future<Output = Result<(), Error>> + Send
fn add_role<B: Backend>( &self, ctx: &Context<B>, role_id: RoleId, reason: Option<&str>, ) -> impl Future<Output = Result<(), Error>> + Send
Gives this member a role (MemberManager::add_role).
discord.js counterpart: GuildMemberRoleManager#add.
§Errors
Returns the REST error if the request failed.
Sourcefn remove_role<B: Backend>(
&self,
ctx: &Context<B>,
role_id: RoleId,
reason: Option<&str>,
) -> impl Future<Output = Result<(), Error>> + Send
fn remove_role<B: Backend>( &self, ctx: &Context<B>, role_id: RoleId, reason: Option<&str>, ) -> impl Future<Output = Result<(), Error>> + Send
Takes a role from this member (MemberManager::remove_role).
discord.js counterpart: GuildMemberRoleManager#remove.
§Errors
Returns the REST error if the request failed.
Sourcefn kick<B: Backend>(
&self,
ctx: &Context<B>,
reason: Option<&str>,
) -> impl Future<Output = Result<(), Error>> + Send
fn kick<B: Backend>( &self, ctx: &Context<B>, reason: Option<&str>, ) -> impl Future<Output = Result<(), Error>> + Send
Kicks this member (MemberManager::kick).
discord.js counterpart: GuildMember#kick.
§Errors
Returns the REST error if the request failed.
Sourcefn ban<B: Backend>(
&self,
ctx: &Context<B>,
body: &CreateGuildBan,
reason: Option<&str>,
) -> impl Future<Output = Result<(), Error>> + Send
fn ban<B: Backend>( &self, ctx: &Context<B>, body: &CreateGuildBan, reason: Option<&str>, ) -> impl Future<Output = Result<(), Error>> + Send
Bans this member (MemberManager::ban).
discord.js counterpart: GuildMember#ban.
§Errors
Returns the REST error if the request failed.
Sourcefn permissions<B: Backend>(&self, ctx: &Context<B>) -> Option<Permissions>
fn permissions<B: Backend>(&self, ctx: &Context<B>) -> Option<Permissions>
This member’s permissions in its guild, computed from the cache as Discord applies
them now, a timeout included (Cache::member_permissions,
D-292, D-294). The cache’s current state of the member is used, not this value’s.
None without a cache, or when the cache lacks the guild, the member or one of its
roles (members are not cached by default: enable them in the
CacheConfig). Interactions carry Discord’s own
computation instead (Interaction::member’s
permissions).
discord.js counterpart: GuildMember#permissions.
§Examples
use djs_rs::{model::permissions::Permissions, prelude::*};
// A prefix command for moderators only.
client.on(Events::MessageCreate, |ctx, msg| async move {
let Some(guild_id) = msg.guild_id else { return Ok(()) };
if msg.content.starts_with("!kick ") {
let author = ctx.members(guild_id).fetch(msg.author.id).await?;
let allowed = author
.permissions(&ctx)
.is_some_and(|permissions| permissions.contains(Permissions::KICK_MEMBERS));
if !allowed {
msg.reply(&ctx, "You may not kick members.").await?;
return Ok(());
}
// …
}
Ok(())
});Sourcefn permissions_in<B: Backend>(
&self,
ctx: &Context<B>,
channel_id: ChannelId,
) -> Option<Permissions>
fn permissions_in<B: Backend>( &self, ctx: &Context<B>, channel_id: ChannelId, ) -> Option<Permissions>
This member’s permissions in the channel or thread channel_id of its guild, computed
from the cache as Discord applies them now: the channel’s overwrites (a thread’s
parent’s), the implicit denials (no VIEW_CHANNEL: nothing; no SEND_MESSAGES: no
mentions of everyone, TTS, files or embeds, D-295) and a timeout (D-294)
(Cache::member_permissions_in).
None without a cache, or when the cache lacks the channel (and for a thread, its
parent), the guild, the member or one of its roles; also for a channel of another
guild.
discord.js counterpart: GuildMember#permissionsIn(channel).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".