Thanks to visit codestin.com
Credit goes to github.com

Skip to content

JuanIzn/ModularDiscordBot

Repository files navigation

Modular Discord Bot Skeleton

Discord.js Node.js

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.

Features

  • 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/voice and play-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

Prerequisites

  • Node.js (LTS version or higher is recommended)
  • Git

🚀 Setup and Installation

Follow these steps to get your bot up and running.

1. Get the Code

Clone the repository to your local machine:

git clone <repository-url>
cd <repository-folder>

2. Install Dependencies

Install all the required npm packages:

npm install

3. Configure Environment Variables

This bot uses a .env file to securely store sensitive information like your bot's token.

  1. Create the .env file: Make a copy of the example file and name it .env.

    cp .env.example .env
  2. Find Your Credentials: You need three pieces of information from the Discord Developer Portal.

    • Bot Token: Go to your Application → Bot → Click Reset Token.
    • Client ID: Go to your Application → OAuth2General → Copy the Application 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 (SettingsAdvancedDeveloper Mode), then right-click your server's icon and click Copy Server ID.
  3. Edit the .env file: Open the .env file 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

4. Deploy Slash Commands

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.js

You should see a message confirming that the commands were successfully reloaded.

5. Start the Bot

You're all set! Start the bot with the following command:

node index.js

If 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.


Project Structure Explained

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published