How to Host a Discord.js v14 Bot 24/7 with Node.js 22 LTS: Production Guide
Complete guide to developing and deploying a Discord.js v14 bot: Slash commands registration, GatewayIntentBits configuration, PM2 supervisor, and 24/7 free cloud hosting on CoalByte.

#Modern Discord Bot Architecture with Discord.js v14
Discord.js version 14 is built natively on modern Node.js standards, utilizing ECMAScript modules, the REST API v10, and typed Gateway Intents. If you are building a moderation bot, music bot, or community economy system, hosting your bot on a reliable 24/7 cloud container is required to keep your users engaged.
In this guide, you will learn how to write a production-ready Discord.js v14 bot and deploy it permanently to CoalByte 100% Free Discord Bot Hosting.
1. Initializing Your Project with Node.js 22 LTS
Create a clean directory and initialize your package.json:
mkdir my-discord-bot && cd my-discord-bot
npm init -y
npm install discord.js dotenvEnsure your package.json specifies "type": "module" to unlock native ES imports:
{
"name": "my-discord-bot",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"discord.js": "^14.16.3",
"dotenv": "^16.4.5"
}
}2. Client Initialization & Gateway Intents
In Discord API v10, bots must explicitly declare the data events they listen to. In index.js:
import { Client, GatewayIntentBits, Events } from 'discord.js';
import dotenv from 'dotenv';
dotenv.config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
]
});
client.once(Events.ClientReady, (readyClient) => {
console.log(`✅ Logged in and online as ${readyClient.user.tag}!`);
readyClient.user.setActivity('Hosted 24/7 on CoalByte Cloud');
});
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'ping') {
const latency = client.ws.ping;
await interaction.reply({
content: `🏓 Pong! WebSocket gateway latency is **${latency}ms**.`,
ephemeral: true
});
}
});
client.login(process.env.DISCORD_TOKEN);3. Registering Slash Commands (Application Commands)
Register your slash commands globally or to your test guild using the Discord REST client:
import { REST, Routes, SlashCommandBuilder } from 'discord.js';
import dotenv from 'dotenv';
dotenv.config();
const commands = [
new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with WebSocket heartbeat latency'),
new SlashCommandBuilder()
.setName('serverinfo')
.setDescription('Displays current server stats and members')
].map(command => command.toJSON());
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN);
try {
console.log('Refreshing application (/) commands...');
await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{ body: commands }
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}4. Deploying 24/7 on CoalByte Free Tier
Deploying to CoalByte takes less than 60 seconds without requiring a credit card:
- Open your CoalByte Free Discord Bot Hosting portal and navigate to Dashboard.
- Click Create Server and choose the Node.js (Discord.js) container.
- Use the web File Manager or connect via SFTP to upload your files (
package.json,index.js). - In the container settings, add your secure environment variables:
DISCORD_TOKEN=your_bot_token_here
CLIENT_ID=your_application_id- Click Start in the live web console.
CoalByte automatically runs npm install, starts your bot using an internal process supervisor, and monitors health around the clock with automated sub-second crash recovery!
Pregătit să testezi găzduirea 24/7 gratuită?
Pornește propriul tău server cu 3 GB RAM dedicat, 2 vCPU, 8 GB SSD și protecție Anti-DDoS în sub 60 de secunde.
