Learn Node.js, Discord.js, the handler, and what each folder does.
Node.js is what runs your bot. It allows JavaScript to run on your computer instead of a browser. Your bot is just a JavaScript program running with Node.js.
node index.js
This command starts your bot.
Discord.js is a library that lets your bot talk to Discord. It listens for events like messages, commands, buttons, and menus.
client.on("interactionCreate", interaction => {
// This runs when a slash command or button is used
});
index.js → Starts the bot and loads the system
app.js → Creates the Discord client and logs into Discord
commands/ → Slash commands (/ping)
context/ → Right-click commands
messages/ → Prefix commands (!ping)
events/ → Discord events (ready, interactionCreate)
buttons/ → Button click handlers
menus/ → Select menu handlers
modals/ → Modal submit handlers
models/ → Database models
schemas/ → Database schemas
utils/ → The handler (loads everything)
logs/ → Error logs
The handler is the system that automatically loads all commands, events, buttons, menus, and modals. Instead of importing every file manually, the handler reads the folders and loads them for you.
Interaction happens
→ events/interactionCreate.js runs
→ Handler checks what the interaction is
→ Handler finds the correct file
→ execute() runs
Every command or button file has an execute() function.
This is the code that runs when the command or button is used.
module.exports = {
name: "ping",
execute(interaction) {
interaction.reply("Pong!");
}
};
index.js starts bot
→ app.js logs into Discord
→ utils handler loads files
→ User runs command
→ events/interactionCreate.js fires
→ Handler finds command file
→ execute() runs
→ Bot replies