Games 2 min read

Host a discord.js bot 24/7: from local code to an online bot

Put a discord.js Discord bot online 24 hours a day: prepare the code, token in a .env, intents, uploading files, npm dependencies and automatic restart.

By Artaun Team

To keep a discord.js bot online 24/7 it must run on an always-on machine, not your PC. Upload your code (without node_modules), install the package.json dependencies, provide the token as an environment variable and start the main file with Node.js. A bot host also restarts it if it crashes.

1. Prepare the code

Keep the token out of your code: in .env write DISCORD_TOKEN=your_token and read it with process.env.DISCORD_TOKEN (via dotenv). Never publish the token: Discord revokes tokens it finds online.

2. Enable intents

If the bot reads message content or the member list, enable the Privileged Gateway Intents in the Discord developer portal (Bot tab), otherwise it stops with Used disallowed intents.

3. Put it online at Artaun

  1. Order a Discord bot; the Micro plan (1 GB) has a 3-day free trial without a card.
  2. During setup choose Node.js, its version and the file to run (index.js).
  3. Upload your code in Files (drag and drop, or a .zip then Extract). Do not upload node_modules.
  4. Open My bot, card Startup file: check index.js.
  5. Card Packages (dependencies): add missing ones.
  6. Card Secret variables (.env): add DISCORD_TOKEN.
  7. Start and watch the Console.

4. Keep it running

Add a global process.on('unhandledRejection', ...) handler, and the Automatic start task in More options > Automatic tasks. Game tools > Analyze recognises common Discord errors (invalid token, intents, rate limits).

5. Resources

Simple command bot: 512 MB to 1 GB. Moderation bot with a few thousand members: 1 to 2 GB. Music or database: 2 to 4 GB.

FAQ

Works locally but not on the server. Usually a missing .env, a different Node.js version or a global dependency absent from package.json.

Do I need a VPS? No, a bot host is enough.

Discord bot hosting, from 0.99 EUR per month.

Ready to get started?

All our plans are commitment-free, delivered in minutes, and hosted in France.