Overview
The @nyx-discord/loaders package provides directory-scanning loaders that automatically discover and instantiate your commands, event subscribers, and schedules from compiled output directories.
Instead of manually importing and registering every project file, you point a loader at a directory and it scans .js / .mjs files, instantiates them, adds them to the Bot, and returns them.
Installation
Installing
npm i @nyx-discord/loadersUsage
Each loader is exposed as a single load() method:
import { , , } from '@nyx-discord/loaders';
const commands = await .({ , : './dist/commands' });
const events = await .({ , : './dist/events' });
const schedules = await .({ , : './dist/schedules' });These returned objects are already added by the loader, they are only returned for informational purposes.
Options
All loaders share a common options interface:
type = {
/** The bot to load objects for. Also passed to static create() methods. */
: ;
/** The directory to scan for .js / .mjs files. */
: string;
/**
* Whether to auto-register loaded objects with the bot.
* @default true
*/
?: boolean;
/**
* Optional filter to include only specific files by their absolute path.
* Files returning false are silently skipped.
*/
?: (: string) => boolean;
};register
Set to false to skip automatic registration and handle it yourself:
import { } from '@nyx-discord/loaders';
const = await .({
,
: './dist/commands',
: false,
});
.().(...);filter
Filter files by their absolute path before they are imported. Useful for excluding tests, dev-only files, or selectively loading subsets:
import { } from '@nyx-discord/loaders';
const = await .({
,
: './dist/events',
: () => !.('.test.') && !.('.spec.'),
});The filter is applied before any file is imported, making it efficient for excluding large numbers of files.
Last updated on
