[−][src]Function twilight_util::link::webhook::parse
pub fn parse(url: &str) -> Result<(WebhookId, Option<&str>), WebhookParseError>
This is supported on crate feature
link
only.Parse the webhook ID and token from a webhook URL, if it exists in the string.
Examples
Parse a webhook URL with a token:
use twilight_model::id::WebhookId; use twilight_util::link::webhook; let url = "https://canary.discord.com/api/webhooks/794590023369752587/tjxHaPHLKp9aEdSwJuLeHhHHGEqIxt1aay4I67FOP9uzsYEWmj0eJmDn-2ZvCYLyOb_K"; let (id, token) = webhook::parse(url)?; assert_eq!(WebhookId(794590023369752587), id); assert_eq!( Some("tjxHaPHLKp9aEdSwJuLeHhHHGEqIxt1aay4I67FOP9uzsYEWmj0eJmDn-2ZvCYLyOb_K"), token, );
Parse a webhook URL without a token:
use twilight_model::id::WebhookId; use twilight_util::link::webhook; let url = "https://canary.discord.com/api/webhooks/794590023369752587"; let (id, token) = webhook::parse(url)?; assert_eq!(WebhookId(794590023369752587), id); assert!(token.is_none());
Errors
Returns WebhookParseError::IdInvalid
if the ID segment of the URL is not
a valid integer.
Returns WebhookParseError::SegmentMissing
if one of the required
segments is missing. This can be the "api" or "webhooks" standard segment
of the URL or the segment containing the webhook ID.