Ping bot (JavaScript)
Replies 'pong' to 'ping'. The smallest useful discord.js bot.
Node.js 22
♥ 0 likes
Environment variables you'll need
| Key | What it is |
|---|---|
DISCORD_TOKEN | Your bot's token from the Discord Developer Portal. Paste it on the Secrets tab; we store it encrypted. |
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" }
}