Project Structure
Project Structure
This document explains the project structure of the Discord bot, including the purpose of each directory and file.
Directory Structure
discord-bot/
├── docs/ # Documentation
├── src/ # Source code
│ ├── commands/ # Bot commands
│ │ ├── General/ # General commands
│ │ ├── Info/ # Info commands
│ │ ├── Information/ # Information commands
│ │ ├── Settings/ # Settings commands
│ │ └── Utility/ # Utility commands
│ ├── components/ # UI component handlers
│ │ └── Utility/ # Utility components
│ ├── events/ # Event handlers
│ │ ├── client/ # Discord client events
│ │ └── cluster/ # Sharding cluster events
│ ├── locales/ # Translation files
│ ├── utils/ # Utility code
│ │ ├── embeds/ # Discord embed templates
│ │ │ └── dynamic/ # Dynamic embed generators
│ │ ├── helpers/ # Helper functions
│ │ ├── managers/ # System managers
│ │ ├── structures/ # Core structures
│ │ └── types/ # TypeScript type definitions
│ ├── Bot.ts # Bot initialization
│ └── index.ts # Entry point with sharding setup
└── dist/ # Compiled JavaScript
Key Files and Directories
Root Files
package.json
- Project configuration and dependenciestsconfig.json
- TypeScript configuration.env
- Environment variables (not in git).env.example
- Example environment variablesREADME.md
- Project overview and setup instructions
Source Code Organization
Commands (src/commands/
)
Commands are organized by category folders. Each command is a single file that exports a command definition:
src/commands/
├── General/ # General commands
│ ├── help.ts
│ └── hello.ts
├── Information/ # Information commands
│ ├── serverinfo.ts
│ └── userinfo.ts
├── Settings/ # Settings commands
│ ├── language.ts
│ └── config.ts
└── Utility/ # Utility commands
├── ping.ts
└── avatar.ts
Components (src/components/
)
Component handlers are organized by type and functionality:
src/components/
└── Utility/ # Utility component handlers
├── confirmButton.ts
└── paginationButtons.ts
Events (src/events/
)
Event handlers are organized by source:
src/events/
├── client/ # Discord client events
│ ├── interactionCreate.ts
│ ├── messageCreate.ts
│ └── ready.ts
└── cluster/ # Sharding cluster events
├── ready.ts
└── error.ts
Locales (src/locales/
)
Localization files for multi-language support:
src/locales/
├── en-US.json # English (United States)
├── de-DE.json # German (Germany)
└── fr-FR.json # French (France)
Utilities (src/utils/
)
Utility code is organized by functionality:
src/utils/
├── embeds/ # Discord embed templates
│ └── dynamic/ # Dynamic embed generators
│ ├── CommandManager.ts
│ └── helpEmbed.ts
├── helpers/ # Helper functions
│ ├── formatters.ts
│ └── validators.ts
├── managers/ # System managers
│ ├── CommandManager.ts
│ ├── ComponentManager.ts
│ ├── CooldownManager.ts
│ ├── EventManager.ts
│ ├── LocaleManager.ts
│ ├── MessageManager.ts
│ └── InteractionManager.ts
├── structures/ # Core structures
│ ├── CommandExecutor.ts
│ ├── DiscordBot.ts
│ └── Logger.ts
└── types/ # TypeScript type definitions
├── commandManager.ts
├── componentManager.ts
└── eventTypes.ts
Core System Files
Bot Initialization
src/index.ts
- Entry point that sets up shardingsrc/Bot.ts
- Bot initialization and client setup
Core Structures
src/utils/structures/DiscordBot.ts
- Main bot class extending Discord.js Clientsrc/utils/structures/CommandExecutor.ts
- Unified command execution interfacesrc/utils/structures/Logger.ts
- Logging utility
Managers
src/utils/managers/CommandManager.ts
- Loads and executes commandssrc/utils/managers/ComponentManager.ts
- Handles UI component interactionssrc/utils/managers/CooldownManager.ts
- Manages command cooldownssrc/utils/managers/EventManager.ts
- Handles event registration and executionsrc/utils/managers/LocaleManager.ts
- Handles translations and localizationsrc/utils/managers/MessageManager.ts
- Processes message commandssrc/utils/managers/InteractionManager.ts
- Processes interaction commands
Localization System
src/locales/*.json
- Translation files in JSON formatsrc/utils/managers/LocaleManager.ts
- Manages loading and using translations
Flow of Execution
index.ts
initializes the botBot.ts
creates an instance ofDiscordBot
DiscordBot
initializes all managers:EventManager
loads event handlersCommandManager
loads commandsComponentManager
loads component handlersLocaleManager
loads translations
- Once the Discord client is ready:
InteractionManager
andMessageManager
are initialized- Commands are registered with Discord API
- The bot processes events, commands, and component interactions as they occur
Adding New Files
Adding a New Command
- Create a new file in the appropriate category folder in
src/commands/
- Export a command definition using the
commandFile
function - The command will be automatically loaded and registered on bot startup
Adding a New Component Handler
- Create a new file in the appropriate category folder in
src/components/
- Export a component definition using the component factory function
- The component handler will be automatically loaded on bot startup
Adding a New Event Handler
- Create a new file in the appropriate event source folder in
src/events/
- Export an event definition using the event factory function
- The event handler will be automatically loaded and registered on bot startup
Adding a New Locale
- Create a new JSON file in
src/locales/
named after the locale code (e.g.,es-ES.json
) - Follow the structure of existing locale files
- The locale will be automatically loaded on bot startup