View Source Nostrum.Token (Nostrum v0.8.0)

A helper module for verifying the Discord bot token.

The token can be generated in the "Bot" tab of your Application the Discord Developer Portal and can be configured in your config file.

config :nostrum,
  token: "666" # The token of your bot as a string

Link to this section Summary

Functions

Checks if the Discord bot token has the correct format.

Link to this section Functions

Checks if the Discord bot token has the correct format.

We check if the token is a binary followed by splitting it into 3 parts separated by a dot ".". The first part is the Base64 encoded user_id which we decode and parse into as integer. The second part is an encoded timestamp, and the last part an arbitrary cryptographic signature.

Raises on failure.

examples

Examples

iex> token = "OTY4NTU2MzQ4MzkwMzkxODU5.G49NjP.pD8PLpKp-Xx8sr-8m1DCxSPTJZdcpcJZOExc1c"
iex> Nostrum.Token.check_token!(token)
:ok

iex> token = "ODY4MDcxODUzMDMyMzU3OTc4.YPqU6Q.jNJcq1daGG3otexX3c1LcxCpgpQ"
iex> Nostrum.Token.check_token!(token)
:ok