Email, messaging and chat

Discord API tokens: find, store, rotate, and use them safely with AI agents

A Discord bot token is on the Bot page of your app in the Developer Portal; click Reset Token to generate one, and Discord cannot show it again. Requests send it as Authorization: Bot <token>. Resetting the token is how you revoke and replace it.

Discord key types

TypePrefixSecret?ScopeExpiry
Bot token
Not viewable after generation; regenerate with Reset Token.
—YesAuthorizes API requests with the permissions and intents your bot app has—

How to create a Discord key

  1. Open your app in the Discord Developer Portal.
  2. In the left sidebar, open the Bot page.
  3. Under Token, click Reset Token.
  4. Copy it into a safe place, such as a password manager. You cannot view it again unless you regenerate it.

Open Discord's key settings

Limiting what the key can do

A bot token carries your app's permissions. Limit the permissions and privileged intents you enable for the bot, and the permissions in the invite link, to what it needs.

How to rotate a Discord key

  1. On the Bot page, click Reset Token.
  2. Update the new token in every deployment and secret store.

The documentation researched does not state whether the old token stops working immediately; assume it does and update callers right away.

How to revoke a Discord key

  1. Click Reset Token on the app's Bot page to generate a new token.

If your Discord key leaked

  1. Reset the bot token on the Bot page.
  2. Update every deployment and secret store with the new token.
  3. Check which servers the bot is in and what it did.

Things that catch people out

  • Bot tokens use the Bot scheme in the Authorization header; OAuth2 tokens use Bearer.
  • Do not commit the token to version control or share it; anyone with it acts as your bot.
  • The token is not viewable after you leave the page.

Common Discord authentication errors

Authentication failed

The token in the Gateway identify payload is incorrect (close code 4004). Reconnecting will not help.

401 Unauthorized

The Authorization header is missing or invalid.

Recent incidents that put Discord keys at risk

If you were affected by one of these, rotate your Discord keys using the rotation steps above.

Using your Discord key with AI agents

A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.

BotPassword works this way. For a Discord key, these intents fit:

IntentWhat BotPassword does
run_withRuns a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output.
http_requestMakes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused.
rotatePartly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet.
store_secretSaves a value the agent already holds as a new vault item.
capture_secretPlanned, not built yet: will read a newly created key straight from the page or command output into the vault.

Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents

Frequently asked questions

Where do I find my Discord bot token?

On the Bot page of your app in the Developer Portal, under Token. If you no longer have it, click Reset Token to generate a new one.

What does a Discord bot token authorization header look like?

Authorization: Bot <token>.

What do I do if my Discord bot token leaks?

Reset it on the Bot page right away and update every place you use it.

Can an AI agent use my Discord key without seeing it?

Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with run_with, http_request, store_secret, so the agent gets the result and never the value.

Stop pasting Discord keys into agents

BotPassword is in early access. Request an invite and we'll email you when your spot opens.