Skip to main content

Variable: TokenRegex

const TokenRegex: RegExp

Regex that can capture a Discord Token

Raw

/(?<mfaToken>mfa\.[a-z0-9_-]{20,})|(?<basicToken>[a-z0-9_-]{23,28}\.[a-z0-9_-]{6,7}\.[a-z0-9_-]{27})/i

Remark

Capture group 1 can be used to retrieve a token for a User that has Multi-Factor Authentication enabled. It is named mfaToken.

Remark

Capture group 2 can be used to retrieve a token for a User that doesn't have Multi-Factor Authentication enabled, or a Bot application. It is named basicToken.

Remark

For a valid token, either Capture group 1 or Capture group 2 will always be undefined, whereas the other group will then be defined and contain the matched token. You can use the name of the capture group to determine if the validated token was configured for a user with Multi-Factor Authentication, for a user without Multi-Factor Authentication, or for a bot application. If both capture groups are undefined, then the token is invalid.

Defined in

projects/utilities/packages/discord-utilities/src/lib/regexes.ts:121