Docs academy · Guide 1 of 8 · 8 min read

Start here: bots, applications and tokens

What a Discord bot really is, how to create an application, and why you never share your token.


What a bot is

A Discord bot is a program you run on a computer that connects to Discord through its API. Discord does not run it for you. If your program stops, your bot goes offline.

Your program does two kinds of talking with Discord:

  • The Gateway is a live connection. Discord pushes events to you as they happen, such as "someone ran a slash command".
  • The REST API is ordinary HTTP. You call it to do things, such as sending a message.

Libraries like discord.js and discord.py handle both for you, so you can write "when this command runs, reply with that".

Create an application

Everything starts in the Discord Developer Portal.

  1. Go to the Developer Portal and log in.
  2. Click New Application, give it a name and accept the terms.
  3. Open the Bot page. Every application created today has a bot user ready.
  4. On the General Information page, copy your Application ID. It's also called the client ID. You'll need it to invite your bot, and later to list it on Nexobots.

Your token

On the Bot page, click Reset Token and copy what you get. Discord only shows it once.

The token is your bot's password. Anyone who has it can control your bot completely. They can read what your bot can read, post as it and ban people in every server that trusted it.

Three rules cover almost every leak:

  1. Keep it out of your code. Put it in a .env file or an environment variable and read it when the program starts.
  2. Keep .env out of Git. Add .env to your .gitignore before your first commit. Bots scan public GitHub repositories for tokens constantly.
  3. Never paste it anywhere, including screenshots, support chats and pastebins. Nobody helping you ever needs it.

Here's a .env file:

DISCORD_TOKEN=paste-your-token-here
DISCORD_CLIENT_ID=your-application-id

And the matching .gitignore:

.env
node_modules/
__pycache__/

If your token leaks

Go to the Bot page and click Reset Token straight away. The old token stops working immediately. Then update your .env and restart your bot.

If you paste something that looks like a token into a Nexobots support ticket, we remove it and tell you to reset it. Treat that warning as real: once a token has been posted anywhere, consider it leaked.

Invite your bot to a server

Bots join servers through an invite link. Make your own test server first, so you can break things in private: in Discord, click the + in the server list.

Then build the link. Replace YOUR_CLIENT_ID with your Application ID:

https://discord.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&permissions=2048&scope=bot+applications.commands
  • scope=bot adds the bot user.
  • scope=applications.commands lets it register slash commands.
  • permissions=2048 is the Send Messages permission. Guide 4 explains how these numbers work.

Open the link, pick your test server and click Authorize. Your bot appears in the member list, offline, because you haven't written any code yet.

Pick a library

Both of these are mature and well documented. Pick the language you already know, or are learning.

| | discord.js | discord.py | | --- | --- | --- | | Language | JavaScript or TypeScript | Python | | Good if | You know some web development | You've written some Python | | Next guide | Your first bot in discord.js | Your first bot in discord.py |

You only need one of the next two guides.

Still stuck? Open a ticket and a mentor will take a look. We'll know which guide you were on.