NewSchokr 13 is here. A whole new UI, seven locations, snapshots and more. Read more →

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

  1. Go to the Discord Developer Portal and sign in with your Discord account.
  2. Create a new application and give it a name. This becomes the bot's default username.
  3. 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

  1. Open the Bot page of your application.
  2. Optionally change the bot's username and avatar.
  3. Click Reset Token and confirm. Discord shows the token once.
  4. 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 .env file 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

SettingWhat it does
Public BotWhen on, anyone with the invite link can add your bot. Turn it off for a private bot.
Requires OAuth2 Code GrantLeave this off unless you have a web backend that handles OAuth2. If it is on, normal invite links fail.
Privileged Gateway IntentsPresence, Server Members and Message Content. Turn on only the ones your code requests. See privileged intents.

Next steps

  1. Invite the bot to your server.
  2. Write the code: discord.js or discord.py.
  3. Deploy it to Schokr: see hosting a Discord bot on Schokr.