This guide starts from zero: you create the bot in Discord, write a small bot that answers !ping and start it on your RHQ Node.js server.
-
Create the application in Discord
Go to the Discord Developer Portal, click New Application, give it a name and confirm.
-
Get the bot token
Open the Bot tab and click Reset Token. Copy the token and keep it to yourself: anyone who has it can control the bot.
On the same page, under Privileged Gateway Intents, turn on Message Content Intent so the bot can read messages.
-
Invite the bot to your Discord server
Open OAuth2 → URL Generator, tick the
botscope and the Send Messages and Read Message History permissions. Open the generated link and pick your server. -
Prepare the project
On your computer, create a folder with three files.
package.json { "name": "my-bot", "main": "index.js", "dependencies": { "discord.js": "^14.16.0", "dotenv": "^16.4.0" } }index.js require('dotenv').config(); const { Client, Events, GatewayIntentBits } = require('discord.js'); const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent], }); client.once(Events.ClientReady, (c) => { console.log(`Logged in as ${c.user.tag}`); }); client.on(Events.MessageCreate, (message) => { if (message.author.bot) return; if (message.content === '!ping') message.reply('Pong!'); }); client.login(process.env.DISCORD_TOKEN);.env DISCORD_TOKEN=paste_your_token_here -
Upload the files to the panel
In the RHQ panel open the Files tab and upload
package.json,index.jsand.env. Do not upload thenode_modulesfolder. -
Set the main file and start
In the Startup tab set the main file to
index.js, then click Start. Dependencies install on the first start. When Console showsLogged in as ..., type!pingin Discord.
Troubleshooting
The bot is online but does not answer !ping
Message Content Intent is off in the Bot tab of the Developer Portal, or GatewayIntentBits.MessageContent is missing from the code.
The console shows "An invalid token was provided"
The token in .env is wrong or was reset. Copy a new one from the Bot tab and restart the server.