discord-hosting.cloud
20% Off First MonthSee prices

Guide

Host a discord.js bot: from Developer Portal to always online

This guide builds a small discord.js v14 bot that answers a slash command, then puts it on a Node.js bot server. Everything here works the same on the free bot tier and on paid plans.

Updated 9 min read

Create the bot in the Developer Portal

  1. 1Create an application

    Open the Discord Developer Portal (discord.com/developers/applications), choose New Application and give it a name.

  2. 2Get the token

    Under Bot, press Reset Token and copy it once. Treat it like a password: anyone with the token controls your bot. See bot token security.

  3. 3Turn on only the intents you need

    Under Privileged Gateway Intents, enable Message Content only if the bot reads message text, and Server Members only if it needs member lists. Slash-command bots usually need neither.

  4. 4Invite the bot

    Under OAuth2, URL Generator, tick the bot and applications.commands scopes, pick the permissions it needs, open the generated link and add the bot to your test server.

Write the bot

discord.js v14 needs a recent Node.js (18 or newer). Create a folder with these three files.

package.json
{
  "name": "my-bot",
  "version": "1.0.0",
  "type": "module",
  "main": "index.js",
  "engines": { "node": ">=18" },
  "scripts": { "start": "node index.js" },
  "dependencies": {
    "discord.js": "^14.16.0",
    "dotenv": "^16.4.0"
  }
}
index.js
import 'dotenv/config';
import { Client, Events, GatewayIntentBits } from 'discord.js';

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.once(Events.ClientReady, (c) => {
  console.log(`Ready as ${c.user.tag} in ${c.guilds.cache.size} servers`);
});

client.on(Events.InteractionCreate, async (interaction) => {
  if (!interaction.isChatInputCommand()) return;
  if (interaction.commandName === 'ping') {
    await interaction.reply(`Pong! ${client.ws.ping} ms`);
  }
});

// Log errors instead of crashing on them.
process.on('unhandledRejection', (err) => console.error('Unhandled rejection:', err));

client.login(process.env.DISCORD_TOKEN);
.env
DISCORD_TOKEN=paste-your-token-here
CLIENT_ID=your-application-id

Register the /ping command once with the script in the slash commands guide. Never commit .env to git: add it to .gitignore.

Put it on the server

  1. 5Create a Node.js bot server

    In the panel, create a Discord bot server with the Node.js (discord.js) option. The free bot tier and the Dirt plan (512 MB) are enough for small bots; see the RAM calculator for bigger ones.

  2. 6Upload the files

    Open Files and upload package.json, index.js and .env (or connect with SFTP). Do not upload node_modules: dependencies install on the server.

  3. 7Check the start file

    On Startup, make sure the start file is index.js (the file named in main).

  4. 8Start and watch the logs

    Start the bot. Dependencies install from package.json on start, then the log should show your ready line. The Bot page can filter the logs to errors and warnings.

    Ready as MyBot#1234 in 1 servers

Next: keep it online 24/7 and secure the token.