← Back to lessons

Lesson 3 — First Slash Command

Goal: Create /ping and see it respond.

Video

Step-by-step

Step 1 — Create a new file

Go to commands/ and create: ping.js

Step 2 — Paste this code
const { SlashCommandBuilder } = require("@discordjs/builders");

module.exports = {
  dev: true, // only registers in DEV_GUILD_ID while learning
  cooldown: 3,
  data: new SlashCommandBuilder()
    .setName("ping")
    .setDescription("Replies with Pong!"),
  async execute(interaction) {
    await interaction.reply("Pong! 🏓");
  },
};
Step 3 — Restart the bot

Stop the bot (Ctrl + C), then:

node index.js
Step 4 — Test in Discord

Go to your dev server and type /ping.

Common mistakes

Completion checklist

← Lesson 2 Next → Lesson 4