bot-tutorial

How to Host a Discord Bot 24/7 for Free (Replit, Railway, VPS)

Learn how to host your Discord bot 24/7 for free using Replit, Railway, or a low-cost VPS—step-by-step setup, troubleshooting tips, and long-term reliability advice.

August 23, 2026 · 882 views

Running a Discord bot isn’t just about writing clean code—it’s about keeping it online all the time. If your bot goes offline every time you close your laptop or reboot your PC, users notice. 🚫⚡ That’s why learning how to host a Discord bot 24/7 for free is one of the most practical skills for any beginner or intermediate developer. In this comprehensive tutorial, we’ll walk through three reliable, free-tier-friendly hosting options: Replit, Railway, and a lightweight VPS (like Oracle Cloud’s forever-free tier). Each method balances ease-of-use, uptime guarantees, and scalability—so whether you're running a simple moderation bot or a full-fledged slash-command RPG, you’ll find the right fit.

We’ll cover everything from environment setup and token security to auto-restart configs and uptime monitoring—no fluff, just actionable steps backed by real-world testing as of August 2026. Let’s get your bot running like a pro! 🛠️

Why Free 24/7 Hosting Matters

Discord bots thrive on consistency. Commands need instant responses. Events like on_message, on_member_join, or scheduled tasks (e.g., daily reminders) require uninterrupted execution. A bot that sleeps when your laptop does isn’t really a bot—it’s a demo. 😅

Free hosting solutions let you validate ideas, build community trust, and iterate without upfront costs. While paid plans offer more CPU/RAM or dedicated IPs, the free tiers of Replit and Railway are more than enough for bots under ~5K servers—and many production-grade bots (including early versions of popular utility bots) started exactly here.

⚠️ Important note: Never hardcode your bot token in source files. We’ll reinforce secure practices at every step.

Option 1: Hosting on Replit (Easiest for Beginners)

Replit is ideal if you want zero-configuration deployment, live editing, and instant preview—all in your browser. As of 2026, Replit’s free tier includes:

  • Always-on mode (with minor idle limits—see below)
  • 512 MB RAM, 1 vCPU
  • Built-in secrets manager (for tokens)
  • Real-time logs & web preview

Step-by-Step Setup

  1. Create a new Python Repl → Go to replit.com, sign in, and click “+ Create Repl”. Choose Python, name it (e.g., my-discord-bot), then hit “Create Repl”.
  2. Install required packages: In the shell, run:
    pip install discord.py python-dotenv
    
  3. Add your bot code: Replace main.py with a minimal working example:
    import os
    import discord
    from discord.ext import commands
    
    intents = discord.Intents.default()
    intents.message_content = True
    bot = commands.Bot(command_prefix="!", intents=intents)
    
    @bot.event
    async def on_ready():
        print(f'✅ {bot.user} is online and ready!')
    
    @bot.command()
    async def ping(ctx):
        await ctx.send('Pong! 🏓')
    
    bot.run(os.getenv("DISCORD_TOKEN"))
    
  4. Store your token securely: Click the lock icon 🔒 in the left sidebar → “Secrets” → add key DISCORD_TOKEN and paste your bot token (from discord.com/developers).
  5. Enable Always-On: Go to Tools → Secrets, then scroll down and toggle “Always-on” (requires account verification—email + phone number). ✅
  6. Run & test: Hit ▶️. Your bot should come online in ~10 seconds.

💡 Pro tip: Replit may pause inactive repls after ~1 hour of silence—but enabling Always-on (and pinging your repl via UptimeRobot or a simple curl cron job) keeps it alive. More on that later.

[Image: Replit dashboard showing Secrets tab with DISCORD_TOKEN added]

Option 2: Hosting on Railway (Best Balance of Simplicity & Reliability)

Railway offers Docker-first deployments with generous free credits ($5/month, effectively unlimited for low-resource bots), persistent logs, automatic HTTPS, and seamless GitHub sync. It’s our top recommendation for bots you plan to maintain long-term.

Step-by-Step Setup

  1. Sign up at railway.app and connect your GitHub account.
  2. Create a new project → Click “New Project”, then “GitHub” → select your bot repo (or create one first).
  3. Structure your repo correctly:
    • main.py (your bot script)
    • requirements.txt (e.g., discord.py==2.3.3)
    • Procfile (required for Railway):
      web: python main.py
      
    • Optional but recommended: .env.example and .gitignore excluding .env
  4. Set environment variable: In Railway dashboard → Variables → add DISCORD_TOKEN (value = your token). Never commit this!
  5. Deploy: Click “Deploy Now”. Railway auto-builds, installs dependencies, and spins up your service.
  6. Verify uptime: Check Logs tab → look for ✅ <bot_name> is online and ready!

✅ Bonus: Railway restarts crashed processes automatically—and unlike Replit, it doesn’t throttle or sleep your service. Your bot stays online truly 24/7.

[Image: Railway dashboard showing active service status and log output]

Option 3: Hosting on a Free Tier VPS (Most Control, Slight Learning Curve)

For developers who want root access, custom firewalls, cron jobs, or multi-bot orchestration, a free VPS is unbeatable. Oracle Cloud offers a forever-free tier: 2 AMD-based VMs (1/2 OCPU, 12 GB total RAM), 200 GB block storage, and 10 TB egress bandwidth/month.

Step-by-Step Setup (Ubuntu 24.04 LTS)

  1. Sign up for Oracle Cloud → Verify identity (ID + credit card for verification only—no charges for free tier).
  2. Launch VM: Go to Compute → Instances → Create Instance.
    • Choose “VM.Standard.E2.1.Micro” (free tier eligible)
    • OS: Ubuntu 24.04 LTS
    • SSH key: Upload your public key (generate with ssh-keygen -t ed25519 if needed)
  3. SSH into your server:
    ssh -i ~/.ssh/your-key.pem ubuntu@<YOUR_VM_IP>
    
  4. Install Python & dependencies:
    sudo apt update && sudo apt upgrade -y
    sudo apt install python3-pip python3-venv git curl -y
    
  5. Clone & set up your bot:
    git clone https://github.com/yourname/your-discord-bot.git
    cd your-discord-bot
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
    
  6. Secure your token with systemd (recommended over .env): Create /etc/environment entry or use systemd environment file:
    sudo nano /etc/systemd/system/discord-bot.service
    
    Paste:
    [Unit]
    Description=Discord Bot
    After=network.target
    
    [Service]
    Type=simple
    User=ubuntu
    WorkingDirectory=/home/ubuntu/your-discord-bot
    ExecStart=/home/ubuntu/your-discord-bot/venv/bin/python /home/ubuntu/your-discord-bot/main.py
    Restart=always
    RestartSec=10
    Environment="DISCORD_TOKEN=your_actual_token_here"
    
    [Install]
    WantedBy=multi-user.target
    
  7. Enable & start the service:
    sudo systemctl daemon-reload
    sudo systemctl enable discord-bot.service
    sudo systemctl start discord-bot.service
    sudo systemctl status discord-bot.service  # verify it's active ✅
    

🔧 Tip: Use journalctl -u discord-bot.service -f to tail logs in real time.

Critical Best Practices (All Methods)

  • Token Security: Never commit DISCORD_TOKEN anywhere—even in .gitignore’d files. Use environment variables exclusively.
  • Error Handling: Wrap bot.run() in try/except and log unhandled exceptions.
  • Uptime Monitoring: Set up free alerts with UptimeRobot (ping your Railway app URL or Replit webview endpoint every 5 min).
  • Rate Limiting Awareness: Discord enforces strict API rate limits. Use @bot.event async def on_ratelimit() to log and respond gracefully.
  • Update Dependencies: Pin versions in requirements.txt (e.g., discord.py==2.3.3) to avoid breaking changes.

Quick Tips

✅ Replit: Add a keep-alive.py script + UptimeRobot ping to prevent idle timeout. ✅ Railway: Use GitHub sync for one-click deploys—ideal for team collaboration. ✅ VPS: Install htop and ncdu to monitor resource usage; most Discord bots use <100 MB RAM. ✅ All methods: Add a /status slash command that returns uptime (time.time() - start_time) and shard info. ✅ Bonus: For advanced logging, pipe stdout to systemd (VPS) or use logging.basicConfig() with RotatingFileHandler.

FAQ

Q: Will my free-tier bot get banned for high API usage?
A: No—if you follow Discord’s API Guidelines. Avoid spammy loops or unthrottled bulk actions. Use asyncio.sleep() where appropriate.

Q: Can I host multiple bots on one Railway project?
A: Yes—but each needs its own service (separate Procfile + env vars). Better practice: one project per bot for clarity.

Q: Does Oracle Cloud really stay free forever?
A: Yes—as long as you stay within the always-free limits (1 VM, 12 GB RAM total across instances, no ARM shapes). Monitor usage in the Console > “Usage Reports”.

Q: What if my bot crashes silently?
A: Add health checks: log on_connect, on_resumed, and on_disconnect; send alerts via webhook (e.g., on crash → post to a private channel). Tools like DiscordCraft offer open-source boilerplates with built-in error telemetry and graceful restart logic.

Final Thoughts

Hosting a Discord bot 24/7 for free isn’t magic—it’s about choosing the right tool for your skill level and growth goals. Replit gets you live in minutes 🌟. Railway gives you production-grade resilience without complexity 🚀. And a free VPS hands you full control—perfect for learning DevOps fundamentals while scaling confidently.

No matter which path you pick, remember: uptime is earned, not assumed. Monitor, log, iterate, and celebrate every ✅ on_ready—because behind every smooth Discord experience is a well-hosted bot doing quiet, reliable work.

Ready to go further? Check out DiscordCraft for battle-tested templates, CI/CD workflows for bots, and community-run uptime dashboards. Happy coding—and even happier hosting! 💫