Back to Wiki

Discord Bot Creation Basics: Build Your First Bot

ayo

ayo

Published April 29, 2026Updated April 29, 2026

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

  1. Go to discord.com/developers/applications
  2. Click "New Application" and give it a name
  3. Go to the "Bot" tab → "Add Bot"
  4. Copy your bot token (keep it secret!)
  5. Under Privileged Gateway Intents, enable:
- Message Content Intent (to read messages) - Server Members Intent (to track members)

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

  1. In the Developer Portal, go to OAuth2 → URL Generator
  2. Check "bot" and "applications.commands"
  3. Select required permissions
  4. 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

Add your bot to public servers and list your community on Discords.ai to grow your audience.

Related Guides

Found this helpful? Explore more articles in the wiki.

Join our Discord