Function serenity::utils::parse_emoji[][src]

pub fn parse_emoji(mention: impl AsRef<str>) -> Option<EmojiIdentifier>
Expand description

Retrieves the animated state, name and Id from an emoji mention, in the form of an EmojiIdentifier.

If the emoji usage is invalid, then None is returned.

Examples

Ensure that a valid Emoji usage is correctly parsed:

use serenity::model::id::{EmojiId, GuildId};
use serenity::model::misc::EmojiIdentifier;
use serenity::utils::parse_emoji;

let expected = EmojiIdentifier {
    animated: false,
    id: EmojiId(302516740095606785),
    name: "smugAnimeFace".to_string(),
};

assert_eq!(parse_emoji("<:smugAnimeFace:302516740095606785>").unwrap(), expected);

Asserting that an invalid emoji usage returns None:

use serenity::utils::parse_emoji;

assert!(parse_emoji("<:smugAnimeFace:302516740095606785").is_none());