discord.js bot hosting

The discord.js template uses the Node.js 22/24 image. It runs the file you set as MAIN_FILE, which defaults to index.js. When package.json is present, startup installs production dependencies with npm ci, and falls back to npm install if the lockfile is missing. Dev dependencies stay off the server so the install is smaller.

Sign in with Discord, Google, GitHub, or email and password. Free hosting works with any sign-in method and requires a verified email address. Claim a free bot and pick discord.js, or compare paid limits on the pricing page. Starter starts at $0.99 a month and $9.99 a year. The free tier is enough for a command bot that answers a few requests. A bot that caches a large guild list, or serves a website from the same process, needs a paid allocation.

Project layout

The hello-world logs in, prints a ready line, and replies to a ping. Replace it with your own index once that line shows. Keep the token in the BOT_TOKEN variable. In code, read process.env.BOT_TOKEN and pass it to client.login. Never interpolate the token into a log line. discord.js will also throw if the token is empty, which is the failure you want, because a silent login usually means the process exited before login.

Set the gateway intents you declared in the developer portal. Guilds and guild messages cover a basic command bot. Message content is privileged. If commands never arrive, compare the intent bitfield with the portal checkboxes. A disallowed intent closes the socket and the console shows the close code. Fix the flags and start again. Do not wrap login in a loop that restarts forever. Bots restart automatically after a crash. Repeated crashes pause restarts; check the console before starting again. A tight crash loop is flagged.

Step-by-step: deploy a discord.js bot.

Dependencies

Commit package.json and, when you can, package-lock.json. npm ci is reproducible. A dependency that needs a native build may fail on the image if the toolchain is missing. Prefer a pure JavaScript package. If the install fails, the process does not reach login. Read the npm error, fix the range, and upload again.

Push to deploy

Public GitHub push-to-deploy is on Free and paid plans; private repositories need a paid plan. Connect the GitHub repository from the account page. The form asks for owner/name and the branch. The reply shows the webhook URL and the secret once. In GitHub, add a webhook with content type application/json and only the push event. Set GIT_REPO, GIT_BRANCH, and AUTO_UPDATE to 1 on the server. A private repo requires a paid plan and GIT_TOKEN. The startup script builds a short-lived ask-pass file, fetches that one branch, and hard-resets tracked files to the new commit. It does not run git clean, so data files and a hand-written .env remain. The console line DEPLOY_COMMIT is the sha that was checked out. The host treats a deploy as finished when the server is running again.

Pushes to other branches do not restart anything. A ping from GitHub is only a handshake. A bad signature is rejected. If you rotate the secret, disconnect or replace the webhook on the account page and paste the new secret into GitHub. The previous secret stops matching.

Next step

Ship the hello-world, invite the bot, then replace the files. When the graphs show the process against the memory limit, move to Pro or Plus instead of raising the free server. See pricing.

Plans

  • FreeFree256 MB · Renew every 7 days
  • Starter$0.99512 MB · / month
  • Pro$1.991 GB · / month
  • Plus$3.492 GB · / month

Questions

Which Node version runs discord.js here?

The discord.js template uses the Node.js 22/24 image and runs the main file after installing production dependencies.

Does npm install dev dependencies?

No. Startup uses npm ci or npm install with dev dependencies omitted.

How do I redeploy from GitHub?

Connect a public repo and branch, set auto-update to 1, and push. The webhook restarts the bot on that branch only. Free supports public repositories within its disk limit and deploy rate limit.

Can I keep a .env file when auto-update runs?

Yes. The update resets tracked files and does not delete untracked files, so a .env you did not commit stays in place.