Tutorial

Deploy a Telegram or Discord bot to Railway (step by step)

No server to patch: connect a repository and Railway builds and runs it.

Tutorial2 min readUpdated

GitHubyour repogit pushRailwaybuild (Dockerfile) + runvariablesYour bot24/71BOT_TOKEN lives in Variables, never in the repo2set a usage limit in workspace settings
Figure 1. Railway builds each push and keeps the service running.
  1. Put the bot in a GitHub repository

    curl -LO https://botnetwork.tech/downloads/telegram-grammy.zip
    unzip telegram-grammy.zip -d mi-bot && cd mi-bot
    git init && git add . && git commit -m "first version"
    # create an empty repo on GitHub, then:
    git remote add origin git@github.com:YOUR_USER/mi-bot.git
    git push -u origin main

    Check that .env is listed in .gitignore before the first commit.

  2. Create the Railway project

    Sign in to Railway, choose New Project, then Deploy from GitHub repo and pick your repository. Railway detects the Dockerfile and builds it.

  3. Add the variables

    Open the service, go to Variables and add:

    BOT_TOKEN=123456789:your-real-token
    MODE=polling

    For the discord.js template use DISCORD_TOKEN and CLIENT_ID instead, and run the register script once from your machine.

  4. Deploy and read the logs

    Saving variables triggers a redeploy. Open Deployments, then the latest deploy logs.

    Railway deploy logs (illustration)Building with Dockerfile...Build successfulStarting container@mi_primer_demo_bot running with long polling1image built2bot is live
    Figure 2. What a healthy first deploy looks like in the Deploy Logs view (illustration, not a real screenshot).

    Keep a single replica for long polling: two copies polling the same token cause 409 Conflict.

  5. Optional: switch to webhooks

    In Settings, Networking generate a public domain. Then set:

    MODE=webhook
    WEBHOOK_URL=https://YOUR-SERVICE.up.railway.app/telegram/webhook
    WEBHOOK_SECRET=paste-output-of-openssl-rand-hex-32

    Railway injects PORT; the template listens on it and answers /healthz. Webhooks allow more than one replica.

  6. Understand the cost

    Railway's pricing page (verified 2026-10-19) lists a Hobby plan at $5/month that includes $5 of usage, and usage rates of about $10 per GB of RAM per month and $20 per vCPU per month, billed per second. A small idle bot using around 100 MB of RAM and very little CPU uses roughly $1 of RAM per month by those rates, which fits inside the included usage. This is an estimate: check the Usage page after a few days and set a usage limit. railway.com/pricing

Troubleshooting

  • Build fails on npm ci: commit package-lock.json, or change the Dockerfile to npm install.
  • Bot starts then stops: a variable is missing; the template exits with a clear message in the logs.
  • 409 Conflict: your local copy is still polling with the same token. Stop it.

Compare with other hosts in the hosting comparator.