Trait Mentionable

Source
pub trait Mentionable {
    // Required method
    fn mention(&self) -> Mention;
}
Expand description

Allows something - such as a channel or role - to be mentioned in a message.

Required Methods§

Source

fn mention(&self) -> Mention

Creates a Mention that will be able to notify or create a link to the item.

Mention implements Display, so ToString::to_string() can be called on it, or inserted directly into a format_args! type of macro.

§Examples
use serenity::model::mention::Mentionable;
async fn greet(
    ctx: Context,
    member: Member,
    to_channel: GuildChannel,
    rules_channel: ChannelId,
) -> Result<(), Error> {
    let builder = CreateMessage::new().content(format!(
        "Hi {member}, welcome to the server! \
        Please refer to {rules} for our code of conduct, \
        and enjoy your stay.",
        member = member.mention(),
        rules = rules_channel.mention(),
    ));
    to_channel.id.send_message(ctx, builder).await?;
    Ok(())
}
use serenity::model::mention::Mentionable;
let user = UserId::new(1);
let channel = ChannelId::new(2);
let role = RoleId::new(3);
assert_eq!(
    "<@1> <#2> <@&3>",
    format!("{} {} {}", user.mention(), channel.mention(), role.mention(),),
)

Implementors§