Your bot token is the password to your bot. Anyone who has it can control your bot and anything it has access to.
Use a .env File
Keep your token in a file called .env instead of in your code:
DISCORD_TOKEN=your-token-here
Then load it in your code. In Node.js, use the dotenv package. In Python, use python-dotenv. Upload the .env file to your server with Files or SFTP.
Keep It Off GitHub
Add
.envto your.gitignoreso it's never pushed.If you deploy from GitHub, upload the
.envfile to your server separately.
Be Careful Who Can See It
Anyone with file access on your server can read your
.env. Only give subusers the permissions they need. See Adding subusers to your server.Don't post screenshots of your files or console with the token showing.
Our staff will never ask for your bot token.
If Your Token Leaks
Go to the Discord Developer Portal, open your application, then Bot.
Click Reset Token. The old token stops working straight away.
Put the new token in your
.envfile and restart your bot.
Related Articles
Was this article helpful?
Your feedback helps us improve the documentation. Thanks — we’re glad this article helped. Sorry about that. What were you hoping to find? Thanks — we’ll use your feedback to improve this article.