EN · $ USD
Security, DDoS and Backups

Discord Bot Token Leaked? What to Do Right Now

7 min read Updated: OyunBulut technical team

In short

If your Discord bot token leaked, reset it immediately with Reset Token on your application's Bot tab in the Discord Developer Portal; the old token stops working instantly. Then restart the bot with the new token, check the Audit Log for damage, and close the source of the leak. From now on, keep the token in a .env file instead of your code, and run the bot without unneeded intents or the Administrator permission.

In this guide
  1. What is a bot token, and why is it so dangerous?
  2. Where do tokens usually leak from?
  3. If your token leaked: what to do in the first 15 minutes
  4. Keep the token out of your code: using .env
  5. Securing server access
  6. Prevent leaks up front: scan before you commit
  7. Turn off unneeded intents and permissions
  8. Next step: keep your token on a secure server

If your Discord bot token leaked, the first thing to do, without waiting even a few minutes, is reset the token in the Discord Developer Portal. Resetting instantly invalidates the old token and cuts off the attacker's control of your bot. Then you close the source of the leak, narrow the bot's permissions, and set things up so the token never goes into your code again. This guide covers the incident response step by step, plus lasting ways to protect your bot.

What is a bot token, and why is it so dangerous?

A bot token is the secret key your bot uses to tell Discord "I am this application." Anyone who has the token can log in as your bot, with no password or two-factor authentication required. Whatever permissions your bot has in whatever servers, the attacker gets them too.

The most common real-world abuse scenarios are:

  • Sending DMs with scams or malicious links to every member of the servers the bot is in.
  • Using a bot with the Administrator permission to delete channels and roles and mass-kick members (a "nuke").
  • Using the bot for spam, which gets it restricted by Discord.

In other words, a token leak doesn't just affect your project. It affects every community that trusts your bot.

Where do tokens usually leak from?

  1. Config files pushed to GitHub: A token in config.json, .env, or written directly into index.js gets pushed to a public repository. This is the most common cause.
  2. Git history: Deleting the token from a file and making a new commit isn't enough; the token is still readable in older commits.
  3. Screenshots and code sharing: Code snippets pasted when asking for help, or screens visible on a stream or in a video.
  4. Public online editors: A token written into a file on free platforms where projects are public by default.
  5. Malicious packages and "ready-made bot" files: Token-stealing code hidden inside npm/pip packages you don't trust or downloaded ready-made bots.
  6. A compromised server or computer: Someone who gets into your server through a weak SSH/RDP password can read every file on the disk.

Discord can automatically invalidate bot tokens it detects in public GitHub repositories and notify the application owner with a system message. If your bot suddenly shut down with an "invalid token" error and you have a message like that in your DMs, the leak was detected. Still, don't rely on this mechanism; private repositories, shared screens, and compromised servers aren't covered by that scanning.

If your token leaked: what to do in the first 15 minutes

  1. Reset the token: Open your application in the Discord Developer Portal, go to the Bot tab, and click Reset Token. If your account has two-factor authentication enabled, you'll be asked for a code. The new token is shown only once, so save it straight to a secure place.
  2. Restart the bot with the new token: Put the token in the .env file on your server and restart the process (for example, pm2 restart bot-adi or sudo systemctl restart bot-adi).
  3. Check for damage: Look at the Audit Log in the servers your bot is in. If channels were deleted, roles changed, or members kicked, let the server admins know.
  4. Find the source of the leak: If the repository is public, clean up the files and history that contain the token (see below). If you suspect it leaked from your server, move on to securing server access.
  5. Rotate other connected secrets too: If the same file held a database password, API key, or webhook URL, treat those as leaked as well. Replace all of them.
Removing a reset token from your Git history is good cleanup, but the reset is what actually keeps you safe. Once a secret has been on the internet, always treat it as "burned."

Keep the token out of your code: using .env

The lasting fix is never to write the token into your source code. The standard way to do that is a .env file and environment variables.

Node.js (discord.js)

# .env
DISCORD_TOKEN=buraya-yeni-token
// index.js
require('dotenv').config();
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.login(process.env.DISCORD_TOKEN);

Python (discord.py)

import os
import discord
from dotenv import load_dotenv

load_dotenv()
client = discord.Client(intents=discord.Intents.default())
client.run(os.environ["DISCORD_TOKEN"])

Next, keep the .env file out of Git and commit only an example file with empty values:

# .gitignore
.env
node_modules/
__pycache__/
# .env.example (this one goes in the repo)
DISCORD_TOKEN=

If the token was already committed, adding it to .gitignore doesn't clean the history. You need to clean the history with a tool like git filter-repo and force-push the repository. Because this affects everyone's local copy of the repo, make sure you've reset the token first.

On the server, tighten the file permissions so only the user running the bot can read the token:

chmod 600 /home/botuser/bot/.env
chown botuser:botuser /home/botuser/bot/.env

Securing server access

Keeping the token out of your code doesn't help if your server isn't secure. Anyone with disk access can read the .env file too. If you run your bot on a VDS, follow these basics:

  • Use SSH keys and disable password login: In /etc/ssh/sshd_config, set PasswordAuthentication no and PermitRootLogin prohibit-password.
  • Don't run the bot as root: Create a separate user for the bot. Even if a dependency has a vulnerability, the attacker can't reach the whole system.
  • Firewall: Discord bots don't need inbound connections; in most cases, leaving only the SSH port open is enough.
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw enable
  • Updates: Update the operating system and your bot's dependencies regularly; npm audit lists known vulnerabilities.

For a more detailed hardening checklist, see our game VDS security guide: SSH, RDP, and firewall settings.

Prevent leaks up front: scan before you commit

Human error never fully goes away, so it makes sense to add a check that automatically stops the token from entering your repository. Open-source secret scanners like Gitleaks scan your changes before you commit and stop the commit if they find a string that looks like a token, API key, or password. Install the tool once and hook it into Git's pre-commit hook, and a token you accidentally pasted into config.json gets caught before it ever leaves your computer.

If you use GitHub, also check the Secret scanning and Push protection options in your repository settings. These features can block or warn you about pushes that contain secrets in known formats.

A short day-to-day checklist:

  • Keep the token only in the .env file on your server and in your password manager.
  • Before sharing code when asking for help, remove the token, webhook, and database lines.
  • Close your terminal and the Developer Portal tab when streaming or taking screenshots.
  • If you share your bot's code with others, keep the repository private and grant access per person.
  • Review downloaded ready-made bot files and little-known packages before running them; look for suspicious code that sends requests to outside servers.

Turn off unneeded intents and permissions

You can't fully prevent leaks, but you can limit the damage a leak can do. The principle is simple: the bot should have only the permissions it actually uses.

SettingWhat it doesRecommendation
Administrator permissionLets the bot do anything in the serverNever grant it; select the permissions you need one by one
Message Content IntentReads message contentEnable only if you use prefix commands or a content filter
Server Members IntentMember list and join/leave eventsKeep it off unless you have features like welcome messages or role assignment
Presence IntentMembers' online status and activitiesUnnecessary for most bots
Public BotLets others add the bot to their serversTurn it off for a private bot

Also enable two-factor authentication on your Developer Portal account. If you work as a team, keep the application under a Team instead of a personal account so you can grant and revoke access per person.

Next step: keep your token on a secure server

The last link in token security is where your bot runs. Using a server only you can access, instead of a home PC, shared free platforms, or public editors, significantly reduces the risk. OyunBulut's Discord Bot VDS plans come with KVM virtualization and root access, so you can apply the separate-user, file-permission, and firewall steps above yourself. For a single small or mid-size bot, the OB-DISCORD-1 plan with 2 vCPU and 2 GB RAM is a solid starting point. If your bot drops offline from time to time, check the troubleshooting steps in our Discord bot keeps going offline guide. For setup, follow the guide to deploying a discord.js bot on a VDS, and compare all Discord bot server options.

Frequently asked questions

What happens if my Discord bot token leaks?

Whoever gets the token can log in as your bot and use every permission it has. That can lead to serious damage like mass DM spam or deleted channels.

Will my bot keep running after I reset the token?

No. The old token stops working instantly and the bot disconnects. Put the new token in the .env file on your server and restart the bot.

Is deleting the file from GitHub enough?

No. The token stays readable in older commits. Reset the token first, then, if you want, clean the history with a tool like git filter-repo.

Why is my bot suddenly getting an 'invalid token' error?

The token may have been reset. Discord can invalidate tokens it finds in public repositories and send the owner a system message; get a new token from the Developer Portal.

Is it safe to give my bot the Administrator permission?

It's not recommended. If the token leaks, the attacker can do anything in the server. Selecting only the permissions the bot actually uses limits the damage of a possible leak.

For this guide

Recommended plans

OB-DISCORD-1 and our Discord Bot VDS plans let you keep your token on a root-access KVM server only you can reach, protected by a separate user and a firewall.

OB-DISCORD-1

Recommended

2 GB RAM

$1.96/mo

+VAT

  • Processor2 vCPU
  • ModelAMD Ryzen / Intel
  • Disk30 GB NVMe
  • LocationIstanbul
  • Port: 1G Port
  • Traffic: Fair use
  • Virtualization: KVM
  • Multi-layer DDoS protection

3 GB RAM

$2.26/mo

+VAT

  • Processor4 vCPU
  • ModelAMD Ryzen / Intel
  • Disk35 GB NVMe
  • LocationIstanbul
  • Port: 1G Port
  • Traffic: Fair use
  • Virtualization: KVM
  • Multi-layer DDoS protection

4 GB RAM

$2.55/mo

+VAT

  • Processor4 vCPU
  • ModelAMD Ryzen / Intel
  • Disk40 GB NVMe
  • LocationIstanbul
  • Port: 1G Port
  • Traffic: Fair use
  • Virtualization: KVM
  • Multi-layer DDoS protection

Discord Bot VDS — tüm paketler

Need help with setup?

Send questions about your service in a support ticket, and our technical team will walk you through it step by step.