How to create a Discord bot and get its token
Create a Discord application in the Developer Portal, add a bot user, copy its token and find the application ID you need for slash commands.
Updated · 2 min read
Every Discord bot starts as an application in the Discord Developer Portal. You create the application, which comes with a bot user, then generate a token that your code uses to log in.
Create the application
- Go to the Discord Developer Portal and sign in with your Discord account.
- Create a new application and give it a name. This becomes the bot's default username.
- Accept the Developer Terms of Service and Developer Policy.
On the application's general information page you will see the Application ID (also called the client ID). Copy it somewhere; you need it for invite links and for registering slash commands.
Get the bot token
- Open the Bot page of your application.
- Optionally change the bot's username and avatar.
- Click Reset Token and confirm. Discord shows the token once.
- Copy the token and store it somewhere private, such as a password manager.
If you lose the token, you can't view it again; just reset it and update your bot with the new one. Resetting immediately invalidates the old token.
Treat the token like a password
Anyone with your token can log in as your bot and do anything it has permission to do in every server it is in. So:
- Never paste the token in your code, a screenshot, a support channel or a public repository.
- Keep it in a
.envfile or environment variable. See storing your bot token safely. - If it ever leaks, reset it right away on the Bot page. Discord also automatically resets tokens it detects in public GitHub repositories and sends you a message when it does.
Settings worth checking on the Bot page
| Setting | What it does |
|---|---|
| Public Bot | When on, anyone with the invite link can add your bot. Turn it off for a private bot. |
| Requires OAuth2 Code Grant | Leave this off unless you have a web backend that handles OAuth2. If it is on, normal invite links fail. |
| Privileged Gateway Intents | Presence, Server Members and Message Content. Turn on only the ones your code requests. See privileged intents. |
Next steps
- Invite the bot to your server.
- Write the code: discord.js or discord.py.
- Deploy it to Schokr: see hosting a Discord bot on Schokr.