Bot Uptime

Discord Bot Security Checklist: Protecting Tokens, Intents & Server Permissions

A leaked Discord bot token gives an attacker full control over every permission your bot holds across every server it has joined — including mass-banning members, deleting channels, and spamming phishing links. Following a few disciplined habits eliminates 99% of bot security incidents.

1. Keep Tokens Strictly Out of Code & Public Repositories

Never write your bot token directly in index.js, main.py, or config.json if that folder is connected to Git. Discord and GitHub actively scan public commits for token patterns and revoke leaked tokens, but malicious scraper bots also monitor GitHub in real time and can nuke a server within seconds of an accidental push.

Always place secrets inside a local .env file and add .env to your .gitignore before making your very first commit.

.gitignore
.env
.env.local
node_modules/
__pycache__/
*.sqlite-journal
target/

2. Follow the Principle of Least Privilege

Avoid checking the Administrator box on your bot invite URL unless your bot genuinely requires full administrative access. A music bot or Quran verse bot only needs View Channels, Send Messages, Embed Links, and Voice permissions — never Ban Members or Manage Channels.

For moderation commands, verify BOTH interaction.memberPermissions (checking the caller has BanMembers/ManageMessages) AND role hierarchy (ensuring a junior moderator cannot ban an Admin or Server Owner).

3. Sanitize Mentions and Prevent Eval / Command Injection

Whenever your bot echoes user-provided text (like custom welcome messages, /say commands, or suggestion titles), always pass allowedMentions: { parse: [] } so a malicious user cannot trick your bot into pinging @everyone or @here.

Never pass raw user strings into eval(), child_process.exec(), or os.system(), and always use parameterized SQL queries (? placeholders) when storing user data in SQLite.

  • Rotate your bot token immediately if a co-developer leaves your team.
  • Enable 2FA on the Discord account that owns your Developer Portal application.
  • Keep regular offline backups of your bot source code and database files.

Frequently Asked Questions

What should I do immediately if I accidentally leak my bot token?

Go to the Discord Developer Portal → Bot → click Reset Token immediately. That instantly invalidates the leaked token and disconnects any attacker. Then update .env on your host and restart.

Ready to deploy your bot 24/7?

Launch a custom Discord, Telegram, or WhatsApp container (Python, Node.js, Java, Rust) with Managed Databases and Free AI Agents — or deploy a ready-made Discord bot in 1 click on Bot Uptime.