All articles
discord-botsJanuary 8, 2026·5 min read

How to Host a Discord Bot for Free - Complete Tutorial

Step-by-step guide to hosting your Discord.js bot 24/7 for free. Learn how to create, configure, and deploy your Discord bot on ModVC.

How to Host a Discord Bot for Free

Learn how to host your Discord bot 24/7 for absolutely free using ModVC. This comprehensive tutorial covers everything from creating your bot to deploying it live.

Prerequisites

Before we start, make sure you have:

  • A Discord account
  • Basic knowledge of JavaScript
  • Node.js installed locally (for testing)
  • A text editor (VS Code recommended)

Part 1: Creating Your Discord Bot

Step 1: Create a Discord Application

  1. Go to the Discord Developer Portal
  2. Click "New Application"
  3. Give your application a name
  4. Click "Create"

Step 2: Create the Bot User

  1. In the left sidebar, click "Bot"
  2. Click "Add Bot"
  3. Click "Yes, do it!"

Step 3: Get Your Bot Token

  1. Under the bot username, click "Reset Token"
  2. Copy the token and save it somewhere safe
  3. Never share this token with anyone!

Step 4: Invite Your Bot to a Server

  1. Go to "OAuth2" → "URL Generator"
  2. Select scopes: bot and applications.commands
  3. Select permissions your bot needs
  4. Copy the generated URL
  5. Paste in browser and select your server

Part 2: Writing Your Bot Code

Create Your Project

Create a new folder and initialize npm:

mkdir my-discord-bot
cd my-discord-bot
npm init -y
npm install discord.js

index.js - Basic Bot Structure

const { Client, GatewayIntentBits, Events } = require('discord.js');

// Create a new client instance
const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent,
    ]
});

// When the client is ready
client.once(Events.ClientReady, () => {
    console.log(`✅ Logged in as ${client.user.tag}`);
    console.log(`📊 Serving ${client.guilds.cache.size} servers`);
});

// Reply to messages
client.on(Events.MessageCreate, message => {
    // Ignore bot messages
    if (message.author.bot) return;
    
    // Simple ping command
    if (message.content === '!ping') {
        message.reply('🏓 Pong!');
    }
    
    // Hello command
    if (message.content === '!hello') {
        message.reply(`Hello, ${message.author.username}! 👋`);
    }
});

// Login to Discord
client.login(process.env.DISCORD_TOKEN);

package.json

{
  "name": "my-discord-bot",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "discord.js": "^14.14.1"
  }
}

Part 3: Deploying to ModVC

Step 1: Prepare Your Files

Make sure your project has:

  • index.js (main bot file)
  • package.json (with dependencies)

Step 2: Create a ZIP File

Compress your project folder:

  • Windows: Right-click → Send to → Compressed folder
  • Mac: Right-click → Compress
  • Linux: zip -r bot.zip .

Step 3: Upload to ModVC

  1. Sign in at modvc.org
  2. Go to your Dashboard
  3. Click "Upload Code"
  4. Select your ZIP file
  5. Wait for upload to complete

Step 4: Set Environment Variables

  1. Click the Settings icon
  2. Go to "Environment Variables"
  3. Add: DISCORD_TOKEN = your bot token
  4. Save changes

Step 5: Start Your Bot

  1. Click the "Start" button
  2. Watch the console for startup messages
  3. You should see: "✅ Logged in as YourBot#1234"

Part 4: Advanced Features

Adding Slash Commands

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

// Register commands when bot starts
client.once(Events.ClientReady, async () => {
    const ping = new SlashCommandBuilder()
        .setName('ping')
        .setDescription('Check bot latency');
    
    await client.application.commands.create(ping);
});

// Handle slash command interactions
client.on(Events.InteractionCreate, async interaction => {
    if (!interaction.isChatInputCommand()) return;
    
    if (interaction.commandName === 'ping') {
        const latency = Date.now() - interaction.createdTimestamp;
        await interaction.reply(`🏓 Pong! Latency: ${latency}ms`);
    }
});

Error Handling

// Handle errors gracefully
process.on('unhandledRejection', error => {
    console.error('Unhandled promise rejection:', error);
});

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

Troubleshooting

Bot Not Coming Online?

  1. Check if your token is correct
  2. Verify environment variables are set
  3. Look at console logs for errors

"Missing Intents" Error?

Make sure you enabled required intents in the Developer Portal:

  1. Go to Bot settings
  2. Enable "Message Content Intent"
  3. Restart your bot

"Invalid Token" Error?

  1. Refresh your bot token in Developer Portal
  2. Update the environment variable in ModVC
  3. Restart your bot

Next Steps

  • Add more commands to your bot
  • Implement a database for persistence
  • Add music playback features
  • Create moderation commands

Your Discord bot is now running 24/7 for free! 🎉