BetterDiscord is built as a modular system with three core packages that work together to modify and enhance Discord. This architecture provides a clean separation of concerns and enables reliable injection into the Discord client.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/betterdiscord/betterdiscord/llms.txt
Use this file to discover all available pages before exploring further.
Three-package architecture
BetterDiscord uses a monorepo structure managed by pnpm with three main packages:Injector
The injector package is responsible for the initial injection into Discord. Its primary job is to:- Inject into Discord’s main process
- Load the preload script into Discord’s BrowserWindow
- Set up the foundation for BetterDiscord to run
injector/ folder of the repository.
Preload
The preload package serves as a bridge between Discord’s main process and the renderer process. It:- Runs as Discord’s preload script for the main BrowserWindow
- Sets up cross-context APIs between main and renderer processes
- Provides secure communication channels through IPC
- Exposes necessary functionality to the renderer
preload/ folder.
Renderer application
The renderer is the main payload of BetterDiscord and where most user interaction occurs. This is executed in the renderer context by the injector and handles:- Loading and managing plugins
- Loading and applying themes
- Initializing builtin features
- Managing settings and user preferences
- Providing the BdApi for plugin developers
renderer/ folder.
Startup sequence
When Discord launches with BetterDiscord, the following sequence occurs:Preload executes
The preload script runs before Discord’s renderer code, establishing cross-context APIs.
Key modules
Core
TheCore module (src/betterdiscord/modules/core.ts) orchestrates the entire startup process and manages the lifecycle of all BetterDiscord components.
Settings store
Manages all BetterDiscord settings, including:- Builtin feature toggles
- User preferences
- Plugin and theme states
- Custom CSS configuration
Addon managers
Two specialized managers handle user content:- PluginManager: Loads, enables, disables, and manages JavaScript plugins
- ThemeManager: Loads and applies CSS themes
AddonManager class which provides common functionality like file watching, state persistence, and error handling.
Patcher
The Patcher module enables modification of Discord’s code at runtime by hooking into functions withbefore, after, and instead methods.
DOMManager
Handles all DOM-related operations including:- Injecting styles (BetterDiscord core, custom CSS, themes)
- Observing DOM changes
- Managing class names and attributes
Development workflow
For local development:Renderer changes are picked up on Discord reload, but preload and injector changes require a full Discord restart.
Next steps
Injection system
Learn how BetterDiscord injects into Discord
Addon system
Understand how plugins and themes work
Builtin features
Explore BetterDiscord’s built-in features