Loaders
The entire ZombieClient framework is driven by loaders. A loader is essentially a plugin or module that handles a specific domain of logic.
Built-in Loaders
FileLoader
The FileLoader is responsible for finding .ts and .js files within your project recursively, while respecting an advanced ignore system.
Creating a FileLoader: Because it needs to asynchronously resolve ignore rules, you must use the static async factory:
const fileLoader = await FileLoader.create();Ignore System:
- Filename Prefix: Any file starting with
#(e.g.,#ping.ts) is automatically ignored. .ignore.json: If you create a*.ignore.jsonfile anywhere in your project, it can contain an array of files or directories to ignore.
["old_commands/", "test.ts"]CommandLoader
The CommandLoader handles your slash commands and context menu commands.
const commandLoader = new CommandLoader(client, fileLoader, commandsDir, {
autoDeploy: true,
useGlobal: false,
defaultGuilds: ['123456789'],
defaultCooldown: 5,
});Important Methods:
deploy(): Compares local commands with Discord's API and updates them intelligently without hitting rate limits.listen(): Registers theinteractionCreateevent internally to route commands and handle cooldowns. You MUST call this beforeclient.login().
EventLoader
The EventLoader automatically registers all your Discord.js events.
const eventLoader = new EventLoader(client, fileLoader, eventsDir);It wraps all handlers in a safe try/catch block so that your bot never crashes from an unhandled exception inside an event.
Creating Custom Loaders
You can create your own loader by implementing the ILoader interface. This is perfect for setting up a Database connection, a Redis cache, or an Express API server alongside your bot.
import type { ILoader } from '@thezombiepl/zombieclient/interfaces';
import type ZombieClient from '@thezombiepl/zombieclient';
export class DatabaseLoader implements ILoader {
public readonly name = 'DatabaseLoader';
private readonly client: ZombieClient;
constructor(client: ZombieClient) {
this.client = client;
}
async load(): Promise<void> {
// e.g., await mongoose.connect(process.env.MONGO_URI);
console.log('[DatabaseLoader] Connected to database');
}
}Register it alongside the built-in loaders:
client.registerLoaders([
commandLoader,
eventLoader,
new DatabaseLoader(client)
]);