Keeping your token safe

Your API token is for you and only you. Please make sure that you keep your token secret because if someone else knows your token that means they can make requests as if they are you.

If you do accidentally show your token don't fear as we have filters in place that will catch it and reset your token for you. On the off chance that you expose your token, not in the Python Discord guild, head to https://pixels.pythondiscord.com/authorize to get a new key. Revisiting this webpage will invalidate your old token and create a new one for you.

Fetching your token

API authentication is done using a bearer token in the Authorization header of requests made to the API. To obtain a bearer token for yourself, head to pixels.pythondiscord.com/authorize and follow the instructions to authorise with Discord through their OAuth2 API.

Once you have received your token you can authenticate with the API by setting your Authorization header to something similar to:

Authorization: Bearer {your token}

Storing secrets

You'll want to keep that token safe in your preferred way of storing secrets. If you haven't dealt with storing secrets before you can utilise the widely used .env format.

Here's a brief example of how you can load your token from a .env file with the python-dotenv package:

TOKEN='your_token_here'

Using the token in your code is as simple as this:

from dotenv import load_dotenv
from os import getenv

load_dotenv(".env")

token = getenv("TOKEN")