Trait serenity::model::misc::Mentionable[][src]

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

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

Required methods

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::misc::Mentionable;
async fn greet(
    ctx: Context,
    member: Member,
    to_channel: GuildChannel,
    rules_channel: ChannelId,
) -> Result<(), Error> {
    to_channel
        .id
        .send_message(ctx, |m| {
            m.content(format_args!(
                "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(),
            ))
        })
        .await?;
    Ok(())
}
use serenity::model::misc::Mentionable;
let user: UserId = 1.into();
let channel: ChannelId = 2.into();
let role: RoleId = 3.into();
assert_eq!(
    "<@1> <#2> <@&3>",
    format!("{} {} {}", user.mention(), channel.mention(), role.mention(),),
)

Implementors