Create your first Discord bot with Node.js
Our Node.js Discord bot creation guide was designed to assist you through the stages of developing, configuring, and hosting your bots. Follow each step to register your application in the Discord Developer Portal, build a multi-command bot with embeds, interactive buttons, and moderation, protect your token, and keep it running 24/7 on LoisaX.
Ce que vous allez apprendre :
- Create and configure an application in the Discord Developer Portal.
- Develop your own multi-command bot using Node.js.
- Configure and protect your authentication token.
- Prepare the required files for cloud hosting.
- Publish your application on LoisaX.
- Keep your bot running continuously 24/7.
Download the complete example bot (7 commands + buttons + moderation)
A complete discord.js 14 + Node.js 22 bot with /ping, /online, /servidor, /usuario, /lembrete, /limpar, and /ajuda with interactive buttons, cooldown protection, and clean SIGTERM shutdown.
Étape 01
Create and configure an application in the Discord Developer Portal
Start in the official Discord Developer Portal (discord.com/developers/applications). Click **New Application**, choose a name for your bot, and confirm.
Under **General Information**, copy the **Application ID** — this becomes your DISCORD_CLIENT_ID used to register slash commands. Next, open the **Bot** tab on the left and click **Reset Token** to generate your DISCORD_TOKEN.
To invite the bot to your test server, open **OAuth2 -> URL Generator**, check both bot and applications.commands, select Send Messages, Embed Links, and Manage Messages, copy the generated URL, and authorize it in your server.
Include the applications.commands scope
Always select applications.commands alongside bot in the OAuth2 URL Generator so your slash commands (/) appear inside the server.
Étape 02
Develop your own bot using Node.js
Structuring your bot into dedicated modules makes adding new features straightforward. Our starter project uses four core files: package.json (dependencies and start script), src/index.js (client bootstrap, presence, and lifecycle), src/commands.js (slash command definitions, interactive buttons, and per-user cooldowns), and src/moderation.js (bulk message cleanup with permission checks).
It ships with 7 ready-to-use commands: /ping (WebSocket and API latency embed), /online (formatted uptime, RAM usage in MB, and Node version), /servidor (server stats card), /usuario (member profile lookup), /lembrete (scheduled channel reminder), /limpar (1–100 bulk message moderation purge), and /ajuda (interactive help menu with clickable buttons).
1{2"name": "meu-bot-discord",3"version": "1.2.0",4"private": true,5"type": "module",6"main": "src/index.js",7"scripts": {8"start": "node src/index.js"9},10"engines": {11"node": ">=22"12},13"dependencies": {14"discord.js": "^14.18.0"15}16}
ES Modules in Node.js 22
Using import in your code? Keep "type": "module" in package.json, just like the example above.
Étape 03
Configure and protect your authentication token
Your DISCORD_TOKEN is the master credential for your bot. Never hardcode it inside src/index.js or commit a real .env file to GitHub — Discord automatically revokes exposed tokens within seconds.
Test locally on your machine first by installing dependencies and passing the credentials only for the current terminal session:
1# 1. Instale as dependencias na pasta do projeto2npm install34# 2. Inicie localmente passando o token apenas na sessao atual5DISCORD_TOKEN="seu_token_aqui" DISCORD_CLIENT_ID="seu_client_id_aqui" npm start
Étape 04
Prepare the required files for hosting
Ensure package.json sits at the **root** of your project with "start": "node src/index.js". If you upload via .zip, select the files **inside** your project folder (package.json, package-lock.json, and src/) and exclude node_modules and .env.
Étape 05
Publish your application on LoisaX
Open the LoisaX Console, click **New Application**, connect your GitHub repository or upload your .zip archive (or run loisax deploy from the CLI), add DISCORD_TOKEN and DISCORD_CLIENT_ID under the **Variables** tab, and start the deployment.
1# Opcional: publicacao direta pelo terminal com a LoisaX CLI2loisax login3loisax env set DISCORD_TOKEN="seu_token" DISCORD_CLIENT_ID="seu_client_id"4loisax deploy
Étape 06
Keep your bot running continuously
Once deployed, your live console logs [OK] Bot autenticado como ... and your bot runs 24/7 in an isolated container. Because src/index.js handles SIGTERM by calling client.destroy(), future updates disconnect old sessions cleanly without duplicate responses.
Étape 07
Une erreur ? Les plus fréquentes et leur solution
Error [TokenInvalid]: An invalid token was provided
Cause : Trailing whitespace or quotes around DISCORD_TOKEN, or token revoked by Discord.
Solution : Reset the token in the Discord Developer Portal and paste the raw value into DISCORD_TOKEN.
Error [DisallowedIntents]: Privileged intent provided is not enabled
Cause : Code requests GuildMembers or MessageContent without enabling the toggle in Discord.
Solution : Enable the matching toggle under Bot -> Privileged Gateway Intents.
Étape 08
Questions fréquentes
Global commands register within seconds; press Ctrl + R in Discord if the client cache lags.
Notre engagement envers les développeurs
Chez LoisaX, nous pensons que notre rôle va au-delà de l’hébergement et du cloud computing. Nous souhaitons également contribuer à l’apprentissage et à la progression de notre communauté.
Nous enrichissons continuellement notre catalogue de guides avec de nouveaux contenus sur les langages de programmation, l’intégration d’APIs, l’automatisation et le développement d’applications.
Autres guides pratiques
Tous les guides
Best Discord bot hosting in 2026

VPS or managed hosting for a bot?
