← Back to lessons

Lesson 5 — Events

Goal: React when the bot starts and when messages are sent.

Video

Step-by-step

Step 1 — Find the events folder

Open events/. You’ll see files like ready, messageCreate, interactionCreate.

Step 2 — Add a console log to ready

Open the ready event file and add a log like:

console.log("Bot is ready!");
Step 3 — Add a simple message listener

Open events/messageCreate.js (or equivalent) and add:

if (message.author.bot) return;
if (message.content === "hi bot") {
  await message.reply("Hello!");
}
Step 4 — Restart and test
node index.js

In Discord, type: hi bot

Completion checklist

← Lesson 4 Next → Lesson 6