Discord Bot Creation Basics: Build Your First Bot
Building a Discord bot is a great way to automate tasks, add custom features, and engage your community. This beginner's guide walks you through the process step by step.
What You'll Need
- A Discord account
- Node.js installed (version 18 or later recommended)
- Basic JavaScript knowledge (helpful but not required)
- A text editor (VS Code recommended)
Step 1: Create Your Bot Application
- Go to discord.com/developers/applications
- Click "New Application" and give it a name
- Go to the "Bot" tab → "Add Bot"
- Copy your bot token (keep it secret!)
- Under Privileged Gateway Intents, enable:
Step 2: Set Up Your Project
Create a project folder and initialize it:
mkdir my-discord-bot
cd my-discord-bot
npm init -y
npm install discord.js dotenv
Create a .env file:
DISCORD_TOKEN=your_bot_token_here
Step 3: Write Your First Bot
Create index.js:
require('dotenv').config();
const { Client, GatewayIntentBits, Events } = require('discord.js');
const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, ], });
client.once(Events.ClientReady, () => { console.log(Logged in as ${client.user.tag}!); });
client.on(Events.MessageCreate, (message) => { if (message.author.bot) return; if (message.content === '!hello') { message.reply('Hello there! 👋'); } });
client.login(process.env.DISCORD_TOKEN);
Run your bot:
node index.js
Step 4: Add Slash Commands
Modern Discord bots use slash commands. Here's a simple example:
const { SlashCommandBuilder } = require('discord.js');
// Register the command const command = new SlashCommandBuilder() .setName('ping') .setDescription('Replies with Pong!');
// Handle the command client.on(Events.InteractionCreate, async (interaction) => { if (!interaction.isChatInputCommand()) return; if (interaction.commandName === 'ping') { await interaction.reply('Pong! 🏓'); } });
Step 5: Invite Your Bot to a Server
- In the Developer Portal, go to OAuth2 → URL Generator
- Check "bot" and "applications.commands"
- Select required permissions
- Copy and open the URL → authorize for your server
Step 6: Deploy Your Bot
To keep your bot running 24/7:
- Railway — easy free hosting for Discord bots
- Heroku — popular platform with free tier
- Replit — browser-based coding and hosting
- VPS (DigitalOcean, Linode) — more control, low cost
Learning Resources
- discord.js Guide — official guide
- Discord Developer Docs
- Discord.js Documentation
Add your bot to public servers and list your community on Discords.ai to grow your audience.