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
- Order a Discord bot; the Micro plan (1 GB) has a 3-day free trial without a card.
- During setup choose Node.js, its version and the file to run (
index.js). - Upload your code in Files (drag and drop, or a
.zipthen Extract). Do not uploadnode_modules. - Open My bot, card Startup file: check
index.js. - Card Packages (dependencies): add missing ones.
- Card Secret variables (.env): add
DISCORD_TOKEN. - 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.