A bot token is the secret password that lets your program log in and act as your chat bot.
This guide is for students, hobby coders and anyone who runs a bot on Discord or Telegram. If your club, community or small business uses a bot, whoever holds its token may be able to speak and act as it.
In short
- A bot token works like a key: anyone who has a copy may be able to control your bot.
- Tokens often leak when they are pasted into code, shared projects, screenshots or chat messages.
- If a token leaks, make a new one straight away in Discord's developer site or Telegram's BotFather. After that, the old one should no longer work.
- Keep the token in a settings file that is never shared, and give the bot only the permissions it needs.
What you will learn
- Explain what a bot token is and why it matters.
- Spot a token left somewhere unsafe.
- Replace a leaked token on Discord or Telegram.
- Check what your bot is allowed to do.
- Bot password (bot token)
- a long secret code that your program uses to log in as the bot.
- Bot maker (BotFather)
- Telegram's own tool for creating bots and managing their tokens.
- Settings file (.env)
- a small file on your computer that holds secrets, kept out of shared code.
What is a bot token?
Think of a front door key. The door opens for whoever holds it, and it does not ask who they are. A bot token works the same way.
A chat bot is a program that joins a chat app and acts on its own. It might welcome new members, post game scores or answer questions. To connect to Discord or Telegram, your program shows its bot token. Telegram describes the token as a string that authenticates your bot, not your own account.[1]
A bot is a kind of non-human identity (NHI), an identity used by software rather than a person. Its token is the credential that proves it is the bot.
Where the comparison stops working: you notice when a door key goes missing. A copied token leaves the original in place, so you may not know someone else has it.
Why does it matter?
Telegram warns that a bot token "can be used by anyone to control your bot".[2] Discord says a token carries your app's permissions, so it is highly sensitive.[3] With a stolen token, someone may post spam or scam links as your bot, or use the bot's powers in your server.
If you are learning to code with a bot project
What could happen: you upload your project to a public site with the token inside it.
Check this: search your project for the token before you share it.
If you run a community server
What could happen: a bot with every permission is taken over and bans members or deletes channels.
Check this: look at which permissions each bot in your server holds.
If a small business uses a bot for customers
What could happen: a stranger sends fake messages to your customers as your bot.
Check this: ask who holds the token and where it is stored.
What does it look like?
Here is a made-up bot program for a fictional book club, with the token typed straight into it.
Example only. All values are made up.
# bookclub_bot.py (shared on a public code site) BOT_NAME = "Chapter Chat" TOKEN = "FAKE-TOKEN-0000-EXAMPLE-0000" (1) WELCOME = "Hello, new reader!" # token also pasted in #bot-help chat (2) # bot role: Administrator (3)
- In a real file, this line would contain the bot's working token, typed straight into the code.
- The same token was pasted into a help channel to ask a question.
- The bot was given every permission, though it only posts welcome messages.
Why this is risky: anyone who sees the code or the chat can copy the token. With full admin rights, a stolen token gives them the bot's full power in the server.[4]
The safer way: the code reads the token from a .env settings file that is never uploaded. Discord's own guide says never to share your token or save it in version control.[3] The bot gets only the permissions it needs to post welcome messages.
Example only. All values are made up.
# bookclub_bot.py (safe to share)
TOKEN = read_setting("BOT_TOKEN") # value lives in .env, not here
# .gitignore
.env
How does it work?
Here is the life of a bot token, from the day you create the bot to the day you need to replace its token.
- You create the bot. On Telegram you message BotFather with a command, and it gives you a token.[1] On Discord you make an app in the developer site and press Reset Token to see one.[3]
- You save it once. Discord shows the token only once, and to see it again you must make a new one.[3] Store it in a password manager or your settings file.
- Your program logs in. Each time it starts, the program sends the token to Discord or Telegram to prove it is the bot.
- The bot uses its permissions. It can do whatever its role allows in each server or group, and no more.[4]
- If the token leaks, you replace it. On Telegram, BotFather's token command makes a new one.[2] On Discord, Reset Token does the same.[3] Then you update your settings file and restart the bot so it uses the new token.


A worked example
Dario Kowal is a student who runs a Discord server for a fictional chess club. He wrote a bot that posts match results.
One evening his friend Vida Iyer messages him. "Your bot just posted a link to a free gift card site in every channel. That is not you, is it?"
Dario thinks of the front door key. Someone has a copy of his bot's key. He remembers that last week he uploaded his bot code to a public site to show his class. The token was in the file.
First, he opens the Discord developer site and presses Reset Token. Once the reset has taken effect, the old token should no longer let anyone log in as the bot. He saves the new token in a .env file and restarts the bot.
Next, he deletes the scam posts and warns members not to click the link. He removes the token line from his public code, and adds .env to his .gitignore file so Git does not upload it again.
Then he looks at the bot's role. It had full admin rights, which it never needed. He gives it only the rights to read and send messages in the results channel.
The bot is back to normal the same evening. Vida says a bot with fewer rights would have done much less harm.
Myths and mistakes
| What people think | What is true |
|---|---|
| My bot is tiny, so nobody will bother with it. | A stolen token gives a ready-made way to post in your server. Small bots are still useful for spam. |
| Deleting the line from my code removes the leak. | Old copies and saved versions may still hold it. Make a new token first. |
| Admin rights make set-up easier, so they are fine. | Admin allows every permission.[4] A stolen admin bot can do much more harm. |
| A private chat is a safe place to share a token. | Chats are saved, searched and screenshotted. Treat the token like a password.[1] |
| The token is the same as my own Discord or Telegram password. | It is separate. It logs in the bot, not you, so changing your password does not replace it. |
What can I do this week?
- Search your code, notes and chat history for your bot token.
- Move the token into a
.envfile and list that file in.gitignore. - Check each bot's role, and remove admin rights it does not need.
- Practise the reset steps once, so you know where the button or command is.
- Turn on two-step sign-in for the account that owns the bot.
Checklist
- The bot token is not typed into code, chat or screenshots.
- The token lives in a private settings file or a password manager.
- The settings file is listed in .gitignore.
- The bot has only the permissions it needs.
- You know how to make a new token on your platform.
- The account that owns the bot uses two-step sign-in.
- Anyone who helps run the bot knows to report a leak straight away.
Common questions
What happens if someone gets my bot token?
They may be able to log in as your bot and do anything its permissions allow. That could mean posting spam, reading messages the bot can see or changing your server. Make a new token straight away, so the old one should no longer work.
How do I reset a Discord bot token?
Open your app in the Discord developer site, go to the Bot page and select Reset Token. Copy the new token into your private settings file, then restart your bot. Once the reset has taken effect, the old token should no longer work.
How do I get a new Telegram bot token?
Message BotFather in Telegram and use its token command for your bot. It gives you a new token. Put the new value in your private settings file and restart the program. Telegram says to do this if your token is lost or exposed.
Can I see my Discord bot token again later?
No. Discord shows a new token once. If you lose it, you must reset it and update your program. This is why it helps to save it in a password manager as soon as you create it.
Is it safe to put my bot on a free hosting site?
It can be, if the site has private settings for secrets. Put the token there, not in your code. Check that your project is not public if it holds any settings files, and use only hosts you trust.
Where next?
Ready for the detail? Read the practitioner guide: Discord and Telegram Bot Tokens Security Guide. It goes further into admin roles, integration tokens, logging and a full leak response for both platforms.
Also useful:
- API Keys for Beginners
- Environment Variables and .env Files
- Non-Human Identities for Beginners
- NHI Foundation Level Training
Related NHI Mgmt Group resources: How to Remove Secrets From Git History · API Key Leak Response Playbook · Secrets Management Guide
Key terms
- Bot token
- A secret code that lets a program log in and act as a chat bot.
- Telegram bot token
- The token BotFather gives you to control a Telegram bot.
- Bot identity
- The account a bot uses in an app, separate from the person who made it.
- Secret
- A password, key, token or certificate that software uses to prove who it is.
- Token rotation
- Replacing a token with a new one so the old one stops working.
- Least privilege
- Giving a bot, app or person only the access it needs for its job.
Sources and further reading
- From BotFather to "Hello World". Telegram Bot API documentation, Telegram. https://core.telegram.org/bots/tutorial, accessed 28 Nov 2026.
- Telegram Bot Features. Telegram Bot API documentation, Telegram. https://core.telegram.org/bots/features, accessed 28 Nov 2026.
- Building your first Discord app. Discord Developer documentation, Discord. https://docs.discord.com/developers/quick-start/getting-started, accessed 28 Nov 2026.
- Permissions. Discord Developer documentation, Discord. https://docs.discord.com/developers/topics/permissions, accessed 28 Nov 2026.