Discord Developer PortalTokenPermissions5 min read

Create a Discord bot from scratch

Register your app in the Discord Developer Portal, create a bot user, get the token and invite it to your server with proper permissions.


Introduction

Before deploying a bot you need to create it in the Discord portal. This guide walks you through from application creation to having the bot online in your server.

Step 1: Create the application

  1. Go to Discord Developer Portal
  2. Click New Application
  3. Choose a name for your application (you can change it later)
  4. Accept the terms and click Create

Step 2: Create the bot user

  1. In the sidebar, go to Bot
  2. Click Add BotYes, do it!
  3. Customize the bot's name and avatar

Step 3: Configure intents

Intents determine which events your bot receives:

terminal
✅ Presence Intent — if you need to see user status
✅ Server Members Intent — if you need member events
✅ Message Content Intent — if you read message content

Only enable the ones your bot actually needs to respect user privacy.

Step 4: Get the token

  1. In the Bot section, click Reset Token
  2. Copy the token and store it securely
bash
# Store it in a .env file
echo 'DISCORD_TOKEN=your_token_here' > .env

Important: Never share or commit the token to Git. If it leaks, regenerate it immediately.

Step 5: Generate the invite URL

  1. Go to OAuth2URL Generator
  2. Under Scopes, select:
  • bot
  • applications.commands (for slash commands)
  1. Under Bot Permissions, choose the required permissions:
terminal
Common permissions:
- Send Messages
- Embed Links
- Attach Files
- Read Message History
- Use Slash Commands
- Manage Messages (for moderation)
- Manage Roles (for role systems)
  1. Copy the generated URL and open it in your browser
  2. Select the server where you want to add the bot

Step 6: Verify the invitation

Once invited, the bot appears offline in your server. To bring it online you need to run the code that connects with the token.

Minimal example with discord.js:

javascript
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent
  ]
});

client.once('ready', () => {
  console.log(`Bot connected as ${client.user.tag}`);
});

client.login(process.env.DISCORD_TOKEN);

Permissions calculator

Use the official calculator to generate the permissions integer:

terminal
https://discordapi.com/permissions.html

Or calculate it manually by combining flags with bitwise OR.

Recommendations

  • Create separate applications for development and production
  • Use a test server to test before deploying
  • Enable 2FA on your developer account
  • Review permissions periodically and remove unused ones

Was this guide helpful?