Skip to content
/ Discord-Bot-Template Public template

πŸ€– Modern Discord bot template with TypeScript, Express & MySQL. Features modular design, slash commands, and secure webhook handling. Ready for your next bot project! ⚑

License

Notifications You must be signed in to change notification settings

Dippys/Discord-Bot-Template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DISCORD-BOT-TEMPLATE

Empower Your Discord with Seamless Bot Magic!

license last-commit repo-top-language repo-language-count


Table of Contents


Overview

The Discord-Bot-Template project offers a robust foundation for building interactive Discord bots, streamlining development with pre-configured features like event handling, command management, and API integration. Ideal for developers seeking to create engaging Discord experiences, it ensures code reliability and maintainability, enhancing user interaction and simplifying bot deployment.


Features

Feature Summary
βš™οΈ Architecture
  • Utilizes a modular architecture with singleton patterns for managing core components like Express, Discord, and MySQL.
  • Centralized event management through EventManager to ensure consistent communication between components.
  • Integration of dotenv for environment configuration, enhancing maintainability and reliability.
πŸ”© Code Quality
  • Incorporates Qodana for static code analysis, ensuring adherence to coding standards.
  • Strict type-checking enforced by TypeScript for enhanced code reliability.
  • Consistent dependency management with package-lock.json to prevent version conflicts.
πŸ“„ Documentation
  • Comprehensive setup and usage instructions provided in README.md with npm commands.
  • Codebase primarily written in TypeScript, ensuring clear type definitions and interfaces.
  • Detailed configuration files like tsconfig.json and qodana.yaml for developers.
πŸ”Œ Integrations
  • Seamless integration with Discord.js for bot functionalities.
  • Utilizes express for web server capabilities and API routing.
  • Database interactions managed through mysql2 for efficient data handling.
🧩 Modularity
  • Modular design with separate directories for Discord interactions, events, and API routes.
  • Dynamic loading of interaction modules for easy scalability and maintenance.
  • Encapsulation of logic in managers like DiscordManager and ExpressManager.
πŸ§ͺ Testing
  • Testing facilitated through npm test command, ensuring code reliability.
  • Automated checks integrated into CI/CD pipeline via Qodana.
  • Focus on maintaining high code quality and identifying issues early.
⚑️ Performance
  • Efficient resource management through singleton patterns for core services.
  • Optimized build process with tsconfig.json for streamlined compilation.
  • Use of nodemon for automatic server restarts during development.
πŸ›‘οΈ Security
  • Secure communication with Discord via signature validation using tweetnacl.
  • Environment variables managed securely with dotenv.
  • Adherence to best practices in API and database interactions.

Project Structure

└── Discord-Bot-Template/
    β”œβ”€β”€ README.md
    β”œβ”€β”€ package-lock.json
    β”œβ”€β”€ package.json
    β”œβ”€β”€ qodana.yaml
    β”œβ”€β”€ src
    β”‚   β”œβ”€β”€ discord
    β”‚   β”œβ”€β”€ index.ts
    β”‚   β”œβ”€β”€ lib
    β”‚   └── web
    └── tsconfig.json

Project Index

DISCORD-BOT-TEMPLATE/
__root__
tsconfig.json - Configure TypeScript compiler settings to ensure consistent and strict type-checking across the project
- Establishes the target JavaScript version and module system, enables interoperability between CommonJS and ES modules, and specifies the output directory for compiled files
- By including only the source directory, it streamlines the build process, enhancing code reliability and maintainability within the project's architecture.
qodana.yaml - The qodana.yaml file configures the Qodana static code analysis tool for the project, specifying the inspection profile and linter to be used
- It facilitates automated code quality checks within the CI/CD pipeline, ensuring adherence to coding standards and identifying potential issues early in the development process
- This integration enhances code reliability and maintainability across the entire codebase architecture.
package.json - The package.json file defines the configuration and dependencies for the "discord-bot-multi-template" project
- It specifies the project's main entry point, build and start scripts, and includes essential libraries for Discord bot functionality, such as discord.js and discord-interactions
- Additionally, it incorporates tools for development and type-checking, like TypeScript and nodemon, ensuring a streamlined development process for building and running the Discord bot.
package-lock.json - The `package-lock.json` file is a crucial component of the project, serving as a detailed manifest that ensures consistent dependency management across different environments
- It locks the specific versions of the project's dependencies, as well as their sub-dependencies, to maintain stability and predictability in the build process
- This file is automatically generated and updated by npm, and it plays a vital role in facilitating reproducible builds, which is essential for both development and production environments
- By capturing the exact dependency tree, it helps prevent potential conflicts and discrepancies that might arise from version mismatches, thereby supporting the overall integrity and reliability of the codebase.
src
index.ts - Initialize and orchestrate the core components of the application, including environment configuration, database connection, Discord bot management, and web server setup
- Facilitate event handling and routing, ensuring the application is ready to process requests
- Serve as the entry point that integrates various managers and services, coordinating their interactions to maintain seamless operation within the broader architecture of the project.
web
routes
router.ts - Facilitates the routing mechanism for the web application by integrating and organizing API endpoints
- It serves as a central hub that connects various sub-route modules, specifically handling general API routes and Discord-specific routes
- This structure enhances modularity and maintainability within the codebase, ensuring that different API functionalities are neatly compartmentalized and easily accessible through defined paths.
api
discord.ts - Handles incoming Discord webhook events by verifying request signatures and processing various event types such as application authorization, entitlement creation, and quest user enrollment
- Utilizes middleware to read raw request bodies and emits corresponding events through an event manager
- Ensures secure communication with Discord by validating signatures using a public key, maintaining the integrity and authenticity of the interactions.
index.ts - Defines API routes for the web application, facilitating user data retrieval and handling test requests
- The `/user/:id` route retrieves user information from the database based on the provided ID, while the `/test` route processes incoming data and responds accordingly
- These routes integrate with the broader architecture by enabling client-server communication and database interaction, supporting the application's functionality and user management features.
lib
eventManager.ts - EventManager serves as a centralized hub for managing and dispatching events across the application, ensuring consistent communication between different components
- By implementing a singleton pattern, it provides a single instance for event handling, promoting efficient resource usage and streamlined event management
- This design enhances modularity and decouples components, facilitating easier maintenance and scalability within the project's architecture.
envManager.ts - DotenvManager centralizes the management of environment variables within the project, ensuring consistent access and configuration across different modules
- By implementing a singleton pattern, it guarantees that environment variables are loaded only once, optimizing resource usage
- This approach enhances maintainability and reliability, as it provides a unified interface for retrieving environment variables, supporting default values when necessary, and aligning with the project's architectural goals.
expressManager.ts - ExpressManager serves as a singleton class responsible for managing the Express application within the project
- It initializes the application, sets up middleware, and starts the server, ensuring that only one instance of the Express app is created and used throughout the codebase
- This design pattern promotes efficient resource management and consistent application behavior across different parts of the project.
discordManager.ts - DiscordManager orchestrates the connection and interaction handling with the Discord API within the project
- It manages the Discord client setup, including intents and partials, and initializes command handling through the InteractionHandler
- By ensuring singleton access, it facilitates efficient interaction management, command registration, and event handling, thereby serving as a central component for Discord-related functionalities in the codebase.
mysqlManager.ts - The `mysqlManager.ts` file establishes a singleton pattern for managing database connections within the project
- It provides a centralized mechanism to connect to a MySQL database and retrieve user data by ID
- This approach ensures efficient resource utilization and consistent database access across the codebase, enhancing maintainability and scalability by preventing multiple instances of database connections.
discord
eventHandler.ts - Facilitates the dynamic loading and registration of event modules within the Discord bot architecture
- By scanning a designated directory for event folders, it ensures that each event adheres to a predefined structure before registering it with the EventManager
- This approach promotes modularity and scalability, allowing for easy addition and management of new events without altering the core event handling logic.
types.ts - Defines TypeScript interfaces for handling various Discord interactions within the project, such as slash commands, context menu commands, buttons, modals, select menus, and autocomplete interactions
- These interfaces standardize the structure for executing interactions and events, ensuring consistent implementation across the codebase
- This organization facilitates the integration and management of Discord bot functionalities, enhancing modularity and maintainability.
InteractionHandler.ts - InteractionHandler manages and processes various types of Discord interactions, such as slash commands, buttons, select menus, context menus, modals, and autocomplete interactions
- It dynamically loads these interaction modules from specified directories, registers them with Discord's API, and executes the appropriate response when an interaction occurs, ensuring seamless integration and functionality within the broader Discord bot architecture.
Interactions
select-menus
test
test.ts - Facilitates user interaction within a Discord bot by defining a select menu component that responds to user selections
- Integrates with the broader system to enhance user engagement through interactive elements
- Contributes to the modular architecture by encapsulating specific interaction logic, allowing for easy maintenance and scalability within the Discord bot's interaction handling framework.
autocomplete
fruits
index.ts - Facilitates user interaction by providing an autocomplete feature for fruit names within a Discord bot
- Enhances user experience by suggesting up to five fruit names based on user input, ensuring quick and relevant suggestions
- Integrates seamlessly into the broader architecture by leveraging Discord.js interactions, contributing to a more interactive and responsive bot environment.
buttons
test
test.ts - Facilitates user interaction within a Discord bot by defining a button that triggers a modal with text input fields
- This component enhances user engagement by allowing users to provide input through a structured interface
- It integrates seamlessly into the broader architecture, leveraging Discord.js to manage interactions and modals, thereby contributing to the bot's interactive capabilities and user experience.
slash
fruits
index.ts - The slash command for listing fruits enhances user interaction within the Discord bot by allowing users to select a fruit and receive information about it
- It integrates with Discord's autocomplete feature to improve user experience and streamline the process of selecting options
- This command contributes to the bot's functionality by providing an engaging and interactive way for users to access specific fruit-related information.
test
test.ts - Implements a Discord slash command named "ping" that responds with "Pong!" and provides interactive components like a button and a select menu
- Enhances user interaction by allowing users to choose from PokΓ©mon options such as Bulbasaur, Charmander, and Squirtle
- Serves as a test command within the broader Discord bot framework, demonstrating the integration of interactive elements in command responses.
context-menus
user
test.ts - Facilitates user interaction within the Discord application by implementing a context menu command named 'test'
- Enhances user experience by providing immediate feedback upon selection, confirming successful interaction or notifying of errors
- Integrates seamlessly into the broader architecture by leveraging Discord's application command framework, contributing to the project's goal of creating interactive and responsive Discord bot functionalities.
message
test.ts - Facilitates user interaction within a Discord application by implementing a context menu command named 'testificate'
- Enhances user experience by providing feedback upon interaction, confirming successful execution or reporting errors
- Integrates seamlessly into the broader project architecture, which likely includes various interactive elements, by leveraging Discord's application command framework to handle user-initiated events efficiently and responsively.
modals
test
test.ts - Facilitates user interaction within a Discord application by handling modal submissions
- It captures user input from a modal with specific fields and responds with a message that includes the provided input values
- This functionality enhances user engagement by allowing dynamic data collection and response, contributing to the interactive capabilities of the broader application architecture.
events
ApplicationAuthorized
index.ts - Facilitates user engagement by sending a welcome message and interactive buttons to users upon authorizing the application on Discord
- Enhances user experience by providing options to set up a profile or seek help, integrating seamlessly with the broader Discord bot functionality
- Contributes to the project's goal of creating an interactive and user-friendly environment within the Discord platform.

Getting Started

Prerequisites

Before getting started with Discord-Bot-Template, ensure your runtime environment meets the following requirements:

  • Programming Language: TypeScript
  • Package Manager: Npm

Installation

Install Discord-Bot-Template using one of the following methods:

Build from source:

  1. Clone the Discord-Bot-Template repository:
❯ git clone https://github.com/Dippys/Discord-Bot-Template
  1. Navigate to the project directory:
❯ cd Discord-Bot-Template
  1. Install the project dependencies:

Using npm Β 

❯ npm install

Usage

Copy the .env.example file to .env by using the following command:

cop .env.example .env

Update the .env file with all the information required.

Run Discord-Bot-Template using the following command: Using npm Β 

❯ npm start

Testing

Run the test suite using the following command: Using npm Β 

❯ npm test

Contributing

  • πŸ’¬ Join the Discussions: Share your insights, provide feedback, or ask questions.
  • πŸ› Report Issues: Submit bugs found or log feature requests for the Discord-Bot-Template project.
  • πŸ’‘ Submit Pull Requests: Review open PRs, and submit your own PRs.
Contributing Guidelines
  1. Fork the Repository: Start by forking the project repository to your github account.
  2. Clone Locally: Clone the forked repository to your local machine using a git client.
    git clone https://github.com/Dippys/Discord-Bot-Template
  3. Create a New Branch: Always work on a new branch, giving it a descriptive name.
    git checkout -b new-feature-x
  4. Make Your Changes: Develop and test your changes locally.
  5. Commit Your Changes: Commit with a clear message describing your updates.
    git commit -m 'Implemented new feature x.'
  6. Push to github: Push the changes to your forked repository.
    git push origin new-feature-x
  7. Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
  8. Review: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
Contributor Graph


License

This project is protected under the UNLICENCE License. For more details, refer to the UNLICENCE file.


About

πŸ€– Modern Discord bot template with TypeScript, Express & MySQL. Features modular design, slash commands, and secure webhook handling. Ready for your next bot project! ⚑

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published