Zrzur Developers

Keeping tokens safe

A bot token is a password. Whoever has it acts as your bot in every server it is in.

The rules

  1. Keep the token out of your code. Read it from an environment variable or a secret store.
  2. Never put it in Git, in a screenshot, in a chat or in a support request.
  3. Never log it. Log the bot's id instead.
  4. Use Authenticate on the gateway, not ?token= in the address: addresses end up in logs.
  5. Run the bot with a token of its own. Use a second bot for testing.

Keep it out of Git

echo ".env" >> .gitignore
echo "ZRZUR_BOT_TOKEN=YOUR_BOT_TOKEN" > .env
node --env-file=.env full-bot.mjs

node --env-file is built into Node 22.

If a token leaks

  1. Open your application in the Developer Portal, tab Overview, and choose Reset token.
  2. Confirm your identity. The old token stops at once, and open connections end.
  3. Put the new token in your secret store and restart the bot.
  4. Read the server's audit log for what the bot did. Actions of your bot show the bot as the actor.

Treat a token that was in a public repository as stolen, even if you removed it a minute later.

Other secrets

SecretLives forIf it leaks
Bot tokenuntil you reset itReset it
Interaction token15 minutesOnly works on one interaction. Keep it out of logs
Webhook addressuntil replacedPOST /webhooks/{webhook_id}/token makes a new one. Starts with zrzur_wh_
Signing secretuntil replacedMake a new one in HTTP interactions
OAuth2 client secretuntil resetReset it on the OAuth2 tab
OAuth2 access token1 hourPOST /oauth2/revoke
OAuth2 refresh token30 daysPOST /oauth2/revoke. A reused one ends the whole chain

Protect the people who use your bot

Next