NEWLoisaX CLI 1.4 and 1-command cloud deploys now liveRead post

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.

Updated Nov 27, 2026·15 min read·6 steps

What you will learn:

  • 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.

Step 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.

Step 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.

Step 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 projeto
2npm install
3
4# 2. Inicie localmente passando o token apenas na sessao atual
5DISCORD_TOKEN="seu_token_aqui" DISCORD_CLIENT_ID="seu_client_id_aqui" npm start

Step 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.

Step 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 CLI
2loisax login
3loisax env set DISCORD_TOKEN="seu_token" DISCORD_CLIENT_ID="seu_client_id"
4loisax deploy

Step 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.

Step 07

Got an error? The most common ones, with the fix

Error [TokenInvalid]: An invalid token was provided

Cause: Trailing whitespace or quotes around DISCORD_TOKEN, or token revoked by Discord.

Fix: 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.

Fix: Enable the matching toggle under Bot -> Privileged Gateway Intents.

Step 08

Frequently asked questions

Global commands register within seconds; press Ctrl + R in Discord if the client cache lags.

Community & Education

Our commitment to developers

At LoisaX, we believe our role goes beyond providing hosting and cloud computing services. We also want to contribute to the learning and growth of our developer community.

We are continuously expanding our catalog of guides with new content on programming languages, API integrations, automation, and application development.

More deployment guides

All guides