← Back to lessons

Lesson 4 — Permissions & Cooldowns

Goal: Make a command that only certain people can use, and prevent spam.

Video

Step-by-step

Step 1 — Create a new command file

Create commands/secret.js

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

module.exports = {
  dev: true,
  cooldown: 10,           // 10 seconds between uses per user
  users: ["PUT_YOUR_USER_ID_HERE"], // only these users can run it
  data: new SlashCommandBuilder()
    .setName("secret")
    .setDescription("A locked command for approved users"),
  async execute(interaction) {
    await interaction.reply({ content: "You are allowed to use this command.", ephemeral: true });
  },
};
Step 3 — Get your user ID

Discord → Settings → Advanced → Developer Mode ON → Right-click your name → Copy ID.

Step 4 — Restart and test
node index.js

Run /secret. Then run it again quickly to see cooldown.

Completion checklist

← Lesson 3 Next → Lesson 5