Available Hooks
onBootstrap
Runs when the CommandKit instance is created, before most dependencies are initialized.packages/commandkit/src/commandkit.ts:71
Use Cases
- Register early plugins
- Set up global error handlers
- Initialize logging systems
- Configure environment variables
Characteristics
- ✅ CommandKit instance available
- ❌ Client not yet available
- ❌ Commands/events not loaded
- ❌ Plugins not fully initialized
onApplicationBootstrap
Runs after the CommandKit instance is fully initialized with all dependencies available.packages/commandkit/src/commandkit.ts:87
Use Cases
- Access Discord client
- Query loaded commands/events
- Set up database connections
- Initialize third-party services
- Register dynamic commands
Characteristics
- ✅ CommandKit instance available
- ✅ Client logged in and ready
- ✅ Commands/events loaded
- ✅ Plugins fully initialized
- ✅ All handlers registered
Hook Registration
Type Signatures
packages/commandkit/src/commandkit.ts:48-52
Multiple Hooks
You can register multiple hooks of the same type. They execute sequentially in registration order.Error Handling
Errors in hooks are caught and logged without stopping the application.packages/commandkit/src/commandkit.ts:206-219
Practical Examples
Database Initialization
Feature Flag Setup
Analytics Integration
Dynamic Command Registration
Health Check Endpoint
Plugin Integration
Hooks are commonly used in plugins to initialize functionality.Hook Execution Flow
Timeline
- CommandKit created →
onBootstraphooks run - Dependencies initialize
- Client connects to Discord
- Commands and events load
- Handlers register →
onApplicationBootstraphooks run - Application ready
Best Practices
Choose the Right Hook
Handle Async Operations
Store Services Globally
Log Initialization Steps
Cleanup on Exit
TypeScript Support
Hooks are fully typed with the CommandKit instance.Internal Implementation
Hooks are stored in Sets and executed during application initialization.packages/commandkit/src/commandkit.ts:54-55, 206-219