Function serenity::client::validate_token[][src]

pub fn validate_token(token: impl AsRef<str>) -> Result<()>
Expand description

Validates that a token is likely in a valid format.

This performs the following checks on a given token:

  • At least one character long;
  • Contains 3 parts (split by the period char '.');
  • The second part of the token is at least 6 characters long;
  • The token does not contain any whitespace prior to or after the token.

Examples

Validate that a token is valid and that a number of invalid tokens are actually invalid:

use serenity::client::validate_token;

// ensure a valid token is in fact valid:
assert!(validate_token("Mjg4NzYwMjQxMzYzODc3ODg4.C_ikow.j3VupLBuE1QWZng3TMGH0z_UAwg").is_ok());

// helpful to prevent typos
assert!(validate_token("Njg4NzYwMjQxMzYzODc3ODg4.C_ikow.j3VupLBuE1QWZng3TMGH0z_UAwg").is_err());

Errors

Returns a ClientError::InvalidToken when one of the above checks fail. The type of failure is not specified.