A professional, modular, and feature-rich Discord bot skeleton built with Node.js and the latest version of Discord.js. This project serves as a powerful and clean foundation for creating your own custom Discord bot, suitable for portfolio use.
- Modern & Robust: Built with modern JavaScript (ES6+) and Discord.js v14.
- Fully Modular: A clean and scalable project structure that separates logic into commands, events, and components.
- Slash Commands: Utilizes Discord's latest slash command interactions.
- Dynamic Handlers: Commands and events are loaded dynamically, so adding new ones is as simple as creating a new file.
- Music System: A complete music system powered by
@discordjs/voiceandplay-dl.- Play songs from YouTube (via search or URL).
- Song queue management.
- Automatic disconnect after a period of inactivity.
- Example Commands: Includes a variety of commands to demonstrate different functionalities.
- Utility:
/ping,/user-info - Fun:
/rock-paper-scissors(with interactive buttons) - Music:
/play,/stop,/queue
- Utility:
Follow these steps to get your bot up and running.
Clone the repository to your local machine:
git clone <repository-url>
cd <repository-folder>Install all the required npm packages:
npm installThis bot uses a .env file to securely store sensitive information like your bot's token.
-
Create the
.envfile: Make a copy of the example file and name it.env.cp .env.example .env
-
Find Your Credentials: You need three pieces of information from the Discord Developer Portal.
- Bot Token: Go to your Application →
Bot→ ClickReset Token. - Client ID: Go to your Application →
OAuth2→General→ Copy theApplication ID. - Guild ID (Server ID): This is for testing commands instantly on a specific server. To get it, enable Developer Mode in your Discord settings (
Settings→Advanced→Developer Mode), then right-click your server's icon and clickCopy Server ID.
- Bot Token: Go to your Application →
-
Edit the
.envfile: Open the.envfile and fill in the values you just copied.BOT_TOKEN=YOUR_BOT_TOKEN_HERE CLIENT_ID=YOUR_CLIENT_ID_HERE GUILD_ID=YOUR_SERVER_ID_HERE
Before running the bot, you need to register its slash commands with Discord's API. This script only needs to be run once, or whenever you add/edit a command.
node deploy-commands.jsYou should see a message confirming that the commands were successfully reloaded.
You're all set! Start the bot with the following command:
node index.jsIf everything is configured correctly, you will see "Ready! Logged in as YourBotName#1234" in your console, and the bot will appear online in your server.
The project is organized to be as clear and scalable as possible.
/
├── commands/ # Folder for all command modules
│ ├── music/ # Music-related commands
│ ├── fun/ # Fun/game commands
│ └── utility/ # Utility commands
├── events/ # Event handlers (e.g., when the bot is ready, when an interaction is created)
├── .env # Your private environment variables (ignored by Git)
├── .env.example # An example file for the environment variables
├── .gitignore # Specifies files for Git to ignore
├── README.md # This file!
├── index.js # The main entry point of the bot
├── deploy-commands.js # Script to register slash commands with Discord
└── package.json # Project dependencies and scripts
This structure allows you to add new commands or events simply by creating a new file in the appropriate directory, with no changes needed to index.js.