Ping bot (JavaScript)

Replies 'pong' to 'ping'. The smallest useful discord.js bot.

Node.js 22

Environment variables you'll need

KeyWhat it is
DISCORD_TOKENYour bot's token from the Discord Developer Portal. Paste it on the Secrets tab; we store it encrypted.

Create an account to use it

Files

index.js

const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds,
  GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
client.once('ready', () => console.log('ready'));
client.on('messageCreate', (msg) => {
  if (msg.content === 'ping') msg.reply('pong');
});
client.login(process.env.DISCORD_TOKEN);

package.json

{
  "name": "ping-bot",
  "main": "index.js",
  "engines": { "node": ">=22" },
  "dependencies": { "discord.js": "^14.0.0" }
}