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.
In brief
- Your Discord bot must be hosted in the cloud to run 24/7.
- PM2 ensures your bot stays online by automatically restarting it on crashes.
- In Clodo, select the Node.js version from the panel without CLI setup.
What you need
- An application and bot token created in the Discord Developer Portal
- A service running Node.js (on Clodo the runtime is picked in the panel)
- The bot invited to your guild
On this page
Discord Bots guides
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.
Discord Gateway
Establishes an encrypted WSS websocket session with Discord.
Heartbeat & ACK
Heartbeat packets sustain the connection and compute latency.
PM2 Supervisor
Monitors memory leaks and thread health continuously.
Crash Auto-Recovery
Crashed processes are restarted automatically, with no manual step.
Always-On Bot
The bot keeps running in the background; closing your session does not stop it.
1. Modern Discord.js v14 Starter Template#
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:
npm install -g pm2
pm2 start index.js --name "clodo-bot"
# Sunucu yeniden basladiginda otomatik baslamasi icin:
pm2 startup
pm2 save3. Bot Hosting Methods Compared#
How to Implement This?
Clodo Discord Bot Managed Hosting
Instant Bot Runtime & Web ConsoleZero Linux maintenance; Node.js and Python runtimes are pre-installed with real-time web console.
Step-by-step Execution:
- 1No OS setup required; switch between Node.js 18, 20, 22 in one click.
- 2Store tokens securely inside the encrypted Environment Variables vault.
- 3Built-in watchdog daemon detects unexpected process exits and restarts instantaneously.
- 4View rich colored stdout/stderr streams directly in your browser console.
Frequently Asked Questions
Which setting do I need to enable so my bot can read message content?
You must enable Message Content Intent under the bot settings in the Discord Developer Portal. You also need to include GatewayIntentBits.MessageContent in your code's Client configuration.
Where should I store my bot token instead of the code files?
For security, never hardcode your token into the source code. Store it in startup variables on the runtime tab in the Clodo panel, or in a .env file locally.
How does PM2 behave when the bot encounters an error and crashes?
PM2 supervises the process and automatically restarts the bot upon a crash. To investigate the cause of the failure, inspect the error output in the panel console or PM2 logs.
Will my bot stay online when I turn off my computer?
Yes. Hosting your bot on a server under PM2 or panel supervision ensures it remains online 24/7 even after shutting down your local machine.
Was this guide helpful?
Feedback goes straight to the team that maintains this guide.
Could not find a solution?
You can open a request with our support team from the panel.

