Developing 7/24 Discord.js v14 Bots and Managing with PM2

Step-by-step guide to building a Discord.js v14 bot, slash commands, and hosting it 24/7 using PM2 process manager.

Principiante6 minActualizado:13 de septiembre de 2026
Verificado: discord.js v14Node.js 20 / 22PM2 5.x

Discord.js v14 is the modern standard for Discord bot development, enforcing Gateway Intents and Slash Commands. To keep your bot online when your PC shuts down, it must be hosted 24/7 on a cloud server.

Discord Gateway & PM2 Process Supervisor Pipeline

Persistent websocket connection architecture with sub-second crash recovery managed by PM2.

ARCHITECTURE FLOW
1WEBSOCKET
Discord Gateway

Establishes an encrypted WSS websocket session with Discord.

2CANLI SİNYAL
Heartbeat & ACK

Heartbeat packets sustain the connection and compute latency.

3GÖZCÜ
PM2 Supervisor

Monitors memory leaks and thread health continuously.

4OTO-KURTARMA
Crash Auto-Recovery

Crashed processes are restarted automatically, with no manual step.

5SÜREKLİ ÇALIŞIR
Always-On Bot

The bot keeps running in the background; closing your session does not stop it.

1. Modern Discord.js v14 Starter Template#

index.js
import { Client, GatewayIntentBits } from "discord.js";

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

client.once("ready", () => {
  console.log(`✅ Bot aktif: ${client.user.tag}`);
});

client.on("interactionCreate", async (interaction) => {
  if (!interaction.isChatInputCommand()) return;
  if (interaction.commandName === "ping") {
    await interaction.reply({ content: "🏓 Pong!", ephemeral: true });
  }
});

client.login(process.env.DISCORD_TOKEN);

2. Running 24/7 with PM2 Process Manager#

PM2 is a production process manager that keeps Node.js applications alive forever, auto-restarting them on crashes:

Terminal
npm install -g pm2
pm2 start index.js --name "clodo-bot"
# Sunucu yeniden basladiginda otomatik baslamasi icin:
pm2 startup
pm2 save

3. Bot Hosting Methods Compared#

Comparación de métodos

¿Cómo implementar esto?

Clodo Discord Bot Managed Hosting

Instant Bot Runtime & Web Console

Zero Linux maintenance; Node.js and Python runtimes are pre-installed with real-time web console.

¿Dónde en el panel? Upload your code from Panel > Service detail > 'SFTP & Files', pick the Node.js version on the 'Runtime' tab, then press Start.
Ejecución paso a paso:
  1. 1No OS setup required; switch between Node.js 18, 20, 22 in one click.
  2. 2Store tokens securely inside the encrypted Environment Variables vault.
  3. 3Built-in watchdog daemon detects unexpected process exits and restarts instantaneously.
  4. 4View rich colored stdout/stderr streams directly in your browser console.

¿Te ha resultado útil esta guía?

Los comentarios van directamente al equipo que mantiene esta guía.

¿No encontró una solución?

Puede abrir una solicitud al equipo de soporte desde el panel.

Abrir una solicitud