Module Basics
Modules are self-contained components that handle background tasks, event processing, or provide services to other parts of the bot. Unlike commands, modules don’t directly respond to user input.Module Structure
Module Base Class
All modules extend theModule class from lib/util/module.ts:
lib/util/module.ts:4-19
Basic Module Template
Here’s a minimal module:src/modules/example.ts
Real-World Examples
Stats Collection Module
The AetherStats module collects and sends statistics periodically:src/modules/aetherstats.ts
Content Filtering Module
The Filters module handles message filtering and moderation:src/modules/filters.ts
Module Patterns
Periodic Tasks
Modules often need to run tasks periodically:Event Processing
Modules can process Discord events:Service Provider
Modules can provide services to other parts of the bot:Module Lifecycle
Loading Process
Unloading Process
Accessing Modules
From Commands
From Other Modules
From Listeners
Best Practices
Initialization Order
Wait for dependencies to be ready:Error Handling
Resource Cleanup
Logging
Use the module’s console for logging:[Module:ModuleName] Message
State Management
Module vs Listener
Use a Module when:- You need periodic background tasks
- You’re providing a service to other components
- You have complex stateful logic
- You need lifecycle management
- You’re responding to a specific Discord event
- Logic is event-driven and stateless
- You don’t need periodic execution
Testing Modules
Common Pitfalls
Advanced Patterns
Module Dependencies
Rate Limiting
Caching with TTL
Next Steps
Command Development
Create commands that use your modules
Architecture
Understand how modules fit in Fire’s architecture