Function serenity::utils::parse_username[][src]

pub fn parse_username(mention: impl AsRef<str>) -> Option<u64>
Expand description

Retrieves an Id from a user mention.

If the mention is invalid, then None is returned.

Examples

Retrieving an Id from a valid User mention:

use serenity::utils::parse_username;

// regular username mention
assert_eq!(parse_username("<@114941315417899012>"), Some(114941315417899012));

// nickname mention
assert_eq!(parse_username("<@!114941315417899012>"), Some(114941315417899012));

Asserting that an invalid username or nickname mention returns None:

use serenity::utils::parse_username;

assert!(parse_username("<@1149413154aa17899012").is_none());
assert!(parse_username("<@!11494131541789a90b1c2").is_none());