Module lifecycle
Modules in Zumito Framework expose lifecycle hooks that allow you to execute code at specific moments during the bot’s initialization.
initialize()
Section titled “initialize()”This method is called automatically when the module is loaded. It handles:
- Loading commands from the
commands/folder - Registering events from the
events/folder - Loading translations from the
translations/folder - Registering routes from the
routes/folder
You can override it if you need custom initialization logic, but make sure to call super.initialize():
import { Module } from 'zumito-framework';
export class MyModule extends Module {
async initialize() { await super.initialize(); // Custom initialization code }
}onAllReady()
Section titled “onAllReady()”This hook is called after the entire framework is ready — Discord client connected, all modules loaded, slash commands refreshed, and API server started. It is the ideal place for code that depends on the bot being fully operational.
import { Module } from 'zumito-framework';
export class MyModule extends Module {
async onAllReady() { // Bot is fully ready console.log(`Logged in as ${this.framework.client.user?.tag}`); }
}Framework ready event
Section titled “Framework ready event”As an alternative, you can listen to the ready event emitted by the framework emitter. This is useful when you want to react from an event class without touching the module class:
import { FrameworkEvent } from 'zumito-framework';
export class OnFrameworkReady extends FrameworkEvent {
source = 'framework'; once = true;
async execute(): Promise<void> { console.log('Framework is ready!'); }
}Execution order
Section titled “Execution order”- Discord client connects and emits
ready - Each module’s
initialize()is called - Slash commands are refreshed
- API server starts
- Framework
readyevent is emitted - Each module’s
onAllReady()is called - User callback (configured in
zumito.config.ts) is executed