BetterDiscord uses a sophisticated injection system to modify Discord without altering its original files. This approach allows BetterDiscord to work alongside Discord updates while maintaining compatibility.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.
How injection works
The injection process happens in three stages:Stage 1: Injector
The injector is a local process that modifies Discord’s startup to include BetterDiscord. When you run the BetterDiscord installer or usepnpm inject, it:
- Locates your Discord installation
- Modifies Discord’s entry point to load BetterDiscord’s injector code
- Sets up the necessary file structure in Discord’s app directory
Stage 2: Preload script
When Discord starts, the preload script executes before Discord’s own code:- Runs in an isolated context with special privileges
- Sets up communication between main and renderer processes
- Exposes necessary Node.js functionality to the renderer safely
- Cannot be accessed or modified by Discord’s own code
Stage 3: Renderer execution
After preload completes, the renderer application loads into Discord’s renderer process:The Patcher system
Once injected, BetterDiscord needs to modify Discord’s behavior without changing its source files. This is done through the Patcher system.Patching functions
The Patcher allows intercepting function calls at runtime:Patch types
Before patches
Before patches
Execute code before the original function runs. Useful for:
- Modifying arguments
- Preventing execution based on conditions
- Logging function calls
After patches
After patches
Execute code after the original function completes. Useful for:
- Modifying return values
- Reacting to function results
- Post-processing data
Instead patches
Instead patches
Completely replace a function’s behavior. Useful for:
- Overriding functionality entirely
- Conditional execution of original
- Complex behavior changes
Managing patches
Patches should always be cleaned up:Security model
BetterDiscord’s injection includes several security measures:Sandboxing
The preload script uses Electron’scontextBridge to safely expose functionality:
- Only specific APIs are exposed to the renderer
- Direct Node.js access is restricted
- File system operations are controlled
Secure communication
IPC (Inter-Process Communication) channels are carefully designed:Repair and reinstall
If Discord updates overwrite BetterDiscord’s injection:Development considerations
Testing injection locally
When developing BetterDiscord:Injection changes
Different parts require different reload procedures:| Component | Reload Method |
|---|---|
| Renderer code | Ctrl+R in Discord |
| Preload script | Full Discord restart |
| Injector | Full Discord restart + re-inject |
Most development work happens in the renderer, which only requires a Discord reload (
Ctrl+R), making iteration fast.Next steps
Architecture overview
Understand BetterDiscord’s overall structure
Addon system
Learn how plugins and themes are loaded