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
- Go to the Discord Developer Portal
- Click "New Application"
- Give your application a name
- Click "Create"
Step 2: Create the Bot User
- In the left sidebar, click "Bot"
- Click "Add Bot"
- Click "Yes, do it!"
Step 3: Get Your Bot Token
- Under the bot username, click "Reset Token"
- Copy the token and save it somewhere safe
- Never share this token with anyone!
Step 4: Invite Your Bot to a Server
- Go to "OAuth2" → "URL Generator"
- Select scopes:
botandapplications.commands - Select permissions your bot needs
- Copy the generated URL
- 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
- Sign in at modvc.org
- Go to your Dashboard
- Click "Upload Code"
- Select your ZIP file
- Wait for upload to complete
Step 4: Set Environment Variables
- Click the Settings icon
- Go to "Environment Variables"
- Add:
DISCORD_TOKEN= your bot token - Save changes
Step 5: Start Your Bot
- Click the "Start" button
- Watch the console for startup messages
- 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?
- Check if your token is correct
- Verify environment variables are set
- Look at console logs for errors
"Missing Intents" Error?
Make sure you enabled required intents in the Developer Portal:
- Go to Bot settings
- Enable "Message Content Intent"
- Restart your bot
"Invalid Token" Error?
- Refresh your bot token in Developer Portal
- Update the environment variable in ModVC
- 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! 🎉