Skip to content

agonkolgeci/discord-js-bot-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Discord.js Bot Template (v14)

License Node.js Version Discord.js Version Database Mongoose


Discord.js Bot Template is an ultra-optimized, production-ready Discord bot structure/template designed for Discord.js v14. Utilizing ES6 modules, this boilerplate handles commands, components (buttons, modals, select menus), and events dynamically, enabling you to build stable, scalable, and responsive Discord bots in minutes.

✨ Key Features

  • ⚑ Full ES6 Module Support: Modern import/export syntax throughout the codebase.
  • πŸ“¦ Dynamic Command Loading: Full support for Slash commands, User contexts, and Message contexts.
  • 🧩 Interactive Components Handler: Seamless routing for Buttons, Modals, and Select Menus.
  • πŸ“‘ Automated REST Command Deployments: Automatic registration of application commands to the Discord API.
  • πŸ’Ž Sharding Out-of-the-Box: Effortlessly scale your application with a built-in Sharding Manager.
  • 🎨 Custom Logger: Beautiful, colored console logging powered by Chalk.
  • πŸ› οΈ JSDoc Type Definitions: Full IDE auto-completion suggestions for faster development.
  • πŸƒ Mongoose Integration: Ready-to-go MongoDB connection configuration (completely optional).

πŸ“‚ Project Structure

discord-js-bot-template/
β”œβ”€β”€ .github/
β”‚   └── dependabot.yml       # Automatic weekly dependency updates
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ commands/            # Bot Commands (Slash, Context Menus)
β”‚   β”‚   └── utilities/       # Grouped command folders
β”‚   β”œβ”€β”€ components/          # UI Components (Buttons, Modals, Selects)
β”‚   β”œβ”€β”€ events/              # Event Listeners (client ready, interaction, etc.)
β”‚   β”œβ”€β”€ handlers/            # Core loaders (commands, components, events, rest, DB)
β”‚   β”œβ”€β”€ resources/           # Configuration files
β”‚   β”œβ”€β”€ structure/           # Custom Client class & formatting helpers
β”‚   β”œβ”€β”€ utils/               # Logger & error structures
β”‚   β”œβ”€β”€ index.js             # Main entry point (Normal Mode)
β”‚   └── shard.js             # Sharding entry point (Sharding Mode)
β”œβ”€β”€ .env                     # Private credentials (Token, IDs, DB URI)
β”œβ”€β”€ package.json             # App dependencies & scripts
└── README.md                # This beautiful documentation

πŸš€ Getting Started

πŸ“‹ Prerequisites

πŸ”§ Installation

  1. Clone the Repository:
    git clone https://github.com/agonkolgeci/discord-js-bot-template.git
    cd discord-js-bot-template
  2. Install Dependencies:
    npm install
  3. Setup Environment Variables: Create a .env file in the root directory (or edit the existing one) with your credentials:
    CLIENT_TOKEN=YOUR_DISCORD_BOT_TOKEN
    CLIENT_ID=YOUR_APPLICATION_ID
    MONGO_DB_URI=YOUR_MONGODB_ATLAS_URI # Optional
  4. Configure Bot Settings: Adjust non-sensitive settings in src/resources/config.js:
    export default {
        project: {
            title: "discord-js-bot-template",
            description: "An optimized Discord bot structure...",
            version: "v14"
        },
        messages: {
            formatter: {
                success: "βœ… {message}",
                info: "πŸ“Œ {message}",
                error: "❌ {message}"
            }
        },
        remotes: {
            mongodb: false // Set to true to connect using MONGO_DB_URI
        }
    };

πŸƒ Run Modes

🟒 Normal Mode

Ideal for development and standard single-process bots:

node src/index.js

πŸŒ€ Sharding Mode

Recommended for production and larger bots to manage multi-process scaling:

node src/shard.js

πŸ› οΈ Usage & Architecture

1. Application Commands

Add files containing command objects exported as an array inside any subfolder under src/commands/.

import { SlashCommandBuilder } from "discord.js";

export default [
    {
        structure: new SlashCommandBuilder()
            .setName("ping")
            .setDescription("Replies with Pong!"),
      
        /**
         * @param client {ExtendedClient} - Custom Client instance
         * @param interaction {CommandInteraction} - The command interaction
         */
        onCommand: async (client, interaction) => {
            await interaction.reply("πŸ“ Pong!");
        }
    }
];

2. Interactive Components

Components are captured by their customId and handled dynamically inside any subfolder under src/components/.

export default [
    {
        customId: "example-button",

        /**
         * @param client {ExtendedClient}
         * @param interaction {ButtonInteraction}
         */
        onButton: async (client, interaction) => {
            await interaction.reply({
                content: "You clicked the button!",
                ephemeral: true
            });
        }
    }
];

Supported listeners: onButton, onModalSubmit, onSelectMenu.

3. Event Handling

Events are dynamically registered on the client. Place event files under subfolders of src/events/.

export default [
    {
        name: "ready",
        once: true,

        /**
         * @param client {ExtendedClient}
         */
        onEvent: async (client) => {
            client.logger.log("success", `Logged in as @${client.user.tag}!`);
        }
    }
];

🎨 Utilities & Helpers

πŸ“ Client Message Formatter

Use the built-in formatter from the client to unify the visual style of your user-facing responses:

await interaction.reply({
    content: client.formatter.format("success", "Operation completed successfully!"),
    ephemeral: true
});

πŸͺ΅ Custom Logger

Use the client-level color-coded logging system directly in your code:

client.logger.log("info", "Synchronizing cache...");
client.logger.log("success", "Caching complete!");
client.logger.log("warn", "High memory usage detected >> Optimization recommended.");

πŸ“„ License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

🀝 Credits & Support