Saltearse al contenido
sern

Module

Extended by

Properties

description?

optional description: string

Source

src/types/core-modules.ts:122


locals

locals: Dictionary

Custom data storage object for module-specific information. Plugins and module code can use this to store and retrieve metadata, configuration, or any other module-specific information.

Description

A key-value store that allows plugins and module code to persist data at the module level. This is especially useful for InitPlugins that need to attach metadata or configuration to modules.

Example

1
// In a plugin
2
module.locals.registrationDate = Date.now();
3
module.locals.version = "1.0.0";
4
module.locals.permissions = ["ADMIN", "MODERATE"];

Example

1
// In module execution
2
console.log(`Command registered on: ${new Date(module.locals.registrationDate)}`);

Example

1
// Storing localization data
2
module.locals.translations = {
3
en: "Hello",
4
es: "Hola",
5
fr: "Bonjour"
6
};

Example

1
// Storing command metadata
2
module.locals.metadata = {
3
category: "admin",
4
cooldown: 5000,
5
requiresPermissions: true
6
};

Remarks

  • The locals object is initialized as an empty object ({}) by default
  • Keys should be namespaced to avoid collisions between plugins
  • Values can be of any type
  • Data persists for the lifetime of the module
  • Commonly used by InitPlugins during module initialization

@best-practices

  1. Namespace your keys to avoid conflicts:

    1
    module.locals['myPlugin:data'] = value;
  2. Document the data structure you’re storing:

    1
    interface MyPluginData {
    2
    version: string;
    3
    timestamp: number;
    4
    }
    5
    module.locals['myPlugin:data'] = {
    6
    version: '1.0.0',
    7
    timestamp: Date.now()
    8
    } as MyPluginData;
  3. Use type-safe accessors when possible:

    1
    const getPluginData = (module: Module): MyPluginData =>
    2
    module.locals['myPlugin:data'];

Source

src/types/core-modules.ts:195


meta

meta: object

absPath

absPath: string

id

id: string

Source

src/types/core-modules.ts:123


name?

optional name: string

Source

src/types/core-modules.ts:119


onEvent

onEvent: ControlPlugin<any[]>[]

Source

src/types/core-modules.ts:120


plugins

plugins: InitPlugin<any[]>[]

Source

src/types/core-modules.ts:121


type

type: CommandType | EventType

Source

src/types/core-modules.ts:118

Methods

execute()

execute(…args): any

Parameters

• …args: any[]

Returns

any

Source

src/types/core-modules.ts:196