How to Make a Discord Bot: Complete Step-by-Step Guide (2025)

So you want to build a Discord bot? Honestly, it's way simpler than most people expect. I remember my first bot - it just replied "Hey!" when you said hello. Took me 20 minutes but felt like magic. Whether you're running a gaming clan or study group, bots can automate messages, moderate chats, play music, or even run mini-games. Let me walk you through the whole process without any fluff.

Before Coding: What You Absolutely Need

Don't rush into coding yet. You'll need these three things first:

A Discord Developer Account

Head to Discord's Developer Portal and click "New Application." Name it something memorable - like "PizzaBot" if it'll order pizza (seriously, people have built these).

A Code Editor

Visual Studio Code is my daily driver - free and packed with extensions. But Sublime Text or even Notepad++ work fine for smaller bots. Just pick one you're comfortable with.

Programming Language

Here's where people get stuck. Choose based on your experience:

Language Difficulty Best For Popular Library
JavaScript/Node.js Beginner Most tutorials/resources discord.js (over 1M weekly downloads)
Python Beginner Data-heavy bots discord.py (archived but still used)
Java Intermediate Enterprise applications JDA
C# Intermediate Windows integration DSharpPlus

I recommend Node.js for newbies - it powers about 70% of Discord bots according to top bot lists. Plus, npm (Node's package manager) makes installing dependencies painless.

Creating Your Bot Account Step by Step

Time to make your digital minion! Follow these steps carefully:

Step 1: Create the Application

  • Go to Discord Developer Portal > Applications > New Application
  • Name your bot (you can change this later)
  • Click "Create" - no other fields matter right now

Step 2: Turn It Into a Bot

  • Navigate to the "Bot" tab in left sidebar
  • Click "Add Bot" > "Yes, do it!"
  • Critical step: Under Privileged Gateway Intents, toggle ON "Presence Intent" and "Server Members Intent" if your bot will manage users

Step 3: Get Your Authorization Token

This is your bot's password. Never share it or commit it to GitHub!

  • Under the Bot tab, click "Reset Token"
  • Copy the string that appears (paste it somewhere secure)

⚠️ Warning: If someone gets this token, they can control your bot. I once accidentally posted mine in a public gist - bot started spamming Nazi memes within minutes. Lesson learned.

Step 4: Invite Bot to Your Server

  • Go to "OAuth2" > URL Generator
  • Check "bot" under Scopes
  • Under Bot Permissions, select required access (start with "Administrator" for testing)
  • Copy the generated URL and open in browser
  • Choose your server and authorize

Coding Your First Bot: Let's Get Practical

We'll use Node.js and discord.js here - adjust for other languages. First, install Node.js from their official site if you haven't.

Project Setup

  • Create project folder: mkdir my-bot
  • Open terminal in this folder
  • Initialize npm: npm init -y
  • Install discord.js: npm install discord.js dotenv
  • Create index.js and .env files

Basic "Ping-Pong" Script

Put this in index.js:

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

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('messageCreate', message => {
  if (message.content === '!ping') {
    message.reply('Pong!');
  }
});

client.login(process.env.TOKEN);

In .env add:

TOKEN=Your_Bot_Token_Here

Run with node index.js. Type "!ping" in Discord - it should reply "Pong!"

Adding Basic Commands

Making a bot on Discord gets useful when you add custom commands. Update your code:

client.on('messageCreate', message => {
  if (message.content === '!hello') {
    message.channel.send(`Hey ${message.author.username}!`);
  }
  
  if (message.content === '!serverinfo') {
    message.channel.send(
      `Server name: ${message.guild.name}\nTotal members: ${message.guild.memberCount}`
    );
  }
});

Where to Host Your Bot 24/7

While running locally is fine for testing, your bot sleeps when your computer does. Here are realistic options:

Hosting Option Free Tier Cost for Basic Bot Uptime Guarantee Best For
Replit $0 ~95% Students/hobbyists
Heroku ❌ (since 2022) $7/month 99.9% Small-medium bots
AWS Free Tier ✅ (12 months) $3-15/month after 99.95% Tech-savvy users
Oracle Cloud ✅ (indefinite) $0 98% Budget-focused
Raspberry Pi ✅ (hardware cost) $35 one-time Your home internet Tinkerers

My recommendation? Use Oracle Cloud's free ARM instances. I've hosted 3 bots there for 2 years at zero cost. Setup takes 30 minutes but saves hundreds long-term.

Adding Useful Features

Now that you know the basics of how to make a bot on Discord, let's enhance it:

Moderation Commands

Essential for any community server:

// Kick command
if (message.content.startsWith('!kick')) {
  const user = message.mentions.users.first();
  if (user) {
    const member = message.guild.members.resolve(user);
    member.kick();
    message.channel.send(`${user.tag} kicked`);
  }
}

// Auto-moderation
client.on('messageCreate', message => {
  const bannedWords = ['spam', 'scam', 'http://'];
  if (bannedWords.some(word => message.content.includes(word))) {
    message.delete();
    message.author.send('Your message was removed');
  }
});

Embedded Messages

Make messages visually appealing:

const { EmbedBuilder } = require('discord.js');

client.on('messageCreate', message => {
  if (message.content === '!help') {
    const embed = new EmbedBuilder()
      .setTitle('Commands Guide')
      .setColor('#FF0000')
      .addFields(
        { name: '!ping', value: 'Check bot latency' },
        { name: '!ban @user', value: 'Ban troublemakers' }
      );
    message.channel.send({ embeds: [embed] });
  }
});

Slash Commands (Required Since 2022)

Discord now requires slash commands. Here's how to implement:

const { REST, Routes } = require('discord.js');

const commands = [
  {
    name: 'gif',
    description: 'Sends random gif',
    options: [{ name: 'topic', description: 'Gif topic', type: 3, required: true }]
  }
];

const rest = new REST().setToken(process.env.TOKEN);

(async () => {
  try {
    await rest.put(
      Routes.applicationCommands(CLIENT_ID), 
      { body: commands }
    );
    console.log('Slash commands registered');
  } catch (error) {
    console.error(error);
  }
})();

client.on('interactionCreate', async interaction => {
  if (!interaction.isChatInputCommand()) return;

  if (interaction.commandName === 'gif') {
    const topic = interaction.options.getString('topic');
    await interaction.reply(`https://giphy.com/search/${topic}`);
  }
});

Essential Maintenance Tasks

Building the bot is half the battle. Keep it healthy with these:

Error Logging

Install Sentry or Winston: npm install winston

Basic setup:

const logger = require('winston');
logger.add(new logger.transports.File({ filename: 'errors.log' }));

client.on('error', error => {
  logger.error('Discord API error:', error);
});
        

Performance Monitoring

Check memory usage:

setInterval(() => {
  const mem = process.memoryUsage();
  console.log(`Memory: ${Math.round(mem.heapUsed / 1024 / 1024)}MB`);
}, 60000);
        

Auto-Restart Scripts

Use PM2: npm install pm2 -g

Start bot: pm2 start index.js --name discord-bot

Auto-restart on crash: pm2 startup

Top 5 Mistakes Bot Makers Should Avoid

After helping debug hundreds of bots, I see these constantly:

  1. Hardcoding tokens - Always use .env files and add them to .gitignore
  2. Ignoring rate limits - Discord allows 5 actions per second - exceed this and get banned temporarily
  3. Forgetting error handling - Wrap API calls in try/catch blocks
  4. Overloading with features - Start small. My first bot had 37 commands - nobody used 34 of them
  5. Skipping permissions checks - Verify user roles before executing admin commands

FAQs: Your Bot-Building Questions Answered

Do I need to know coding to make a Discord bot?

Yes, absolutely. Despite what some YouTube videos claim, you can't create functional bots without writing code. Platforms like BotGhost simplify the process but still require JavaScript knowledge.

Can I make money with my Discord bot?

Possible but challenging. Top bots like MEE6 and Dyno monetize through:

  • Premium subscriptions ($3-10/month)
  • Server boosting perks
  • Custom development services

Realistically, expect 6-12 months of free operation before earning anything.

Why won't my bot go online?

Common fixes:

  • Check token in .env matches Developer Portal
  • Enable all required Gateway Intents
  • Install dependencies with npm install
  • Enable "Message Content Intent" for text commands

How much does hosting a Discord bot cost?

For small bots:

  • $0-5/month (Replit/Oracle Cloud)
  • Medium bots: $5-20/month (Heroku/AWS)
  • Large bots: $50-500/month (dedicated servers)

My bot got banned! How do I recover?

Appeal at support.discord.com. Include:

  • Bot application ID
  • Detailed explanation of what happened
  • Steps taken to prevent recurrence

Appeals take 3-14 days. Meanwhile, create a new application and regenerate token.

Next-Level Resources

Ready to go beyond basics? Bookmark these:

  • Official Discord.js Guide: discordjs.guide
  • FreeCodeCamp Bot Tutorial (4-hour video): YouTube
  • Discord API Server: Join server ID 613425648785850370
  • Top Bot Examples: Study Dank Memer (ID 270904126974590976) or Pokétwo (ID 716390085896962058)

Wrapping Up

Learning how to make a bot on Discord is genuinely empowering. Start with a simple ping-pong bot, host it for free on Replit, then gradually add features. The key is iteration - my bot now handles 25,000 users daily, but started as a glorified text responder. When you get stuck (and you will), the Discord API community is surprisingly helpful. Just remember: every bot you see was once someone's first bot project.

Leave a Comments

Recommended Article