Skip to content

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:

typescript
const fileLoader = await FileLoader.create();

Ignore System:

  1. Filename Prefix: Any file starting with # (e.g., #ping.ts) is automatically ignored.
  2. .ignore.json: If you create a *.ignore.json file anywhere in your project, it can contain an array of files or directories to ignore.
json
["old_commands/", "test.ts"]

CommandLoader

The CommandLoader handles your slash commands and context menu commands.

typescript
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 the interactionCreate event internally to route commands and handle cooldowns. You MUST call this before client.login().

EventLoader

The EventLoader automatically registers all your Discord.js events.

typescript
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.

typescript
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:

typescript
client.registerLoaders([
    commandLoader, 
    eventLoader, 
    new DatabaseLoader(client)
]);

Wszelkie prawa zastrzeżone.