Discord bot β Node.js
Discord.js on Node.js 20 LTS with the PM2 process manager, which automatically brings your bot back up after a crash.
Deployment
- Upload your filesUpload the project without the
node_modulesfolder β dependencies are installed frompackage.json. - Set the start fileIn the βStartupβ tab, point to your main file, e.g.
index.js. - Add the token in .envNever put the token directly in your code.
- Start itYou'll see the bot's logs live in the console.
.env
DISCORD_TOKEN=your_bot_token
GUILD_ID=123456789012345678index.js
require('dotenv').config();
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once('ready', () => console.log(`Logged in as ${client.user.tag}`));
client.login(process.env.DISCORD_TOKEN);π
PM2 auto-restartIf the bot throws an unhandled exception, PM2 restarts it in a fraction of a second. You'll find the cause in the console logs.
Was this page helpful?