mirror of
https://github.com/sern-handler/website
synced 2026-06-28 02:32:23 +00:00
init
This commit is contained in:
@@ -21,7 +21,7 @@ title: "ButtonCommand"
|
||||
|
||||
#### Source
|
||||
|
||||
[src/types/core-modules.ts:39](https://github.com/sern-handler/handler/blob/7c8e39defbafdd6312a04a2d30750d647a3ab22b/src/types/core-modules.ts#L39)
|
||||
[src/types/core-modules.ts:122](https://github.com/sern-handler/handler/blob/3f703c17b88b6add7de919772e7b2a7faffd3910/src/types/core-modules.ts#L122)
|
||||
|
||||
***
|
||||
|
||||
@@ -33,7 +33,7 @@ title: "ButtonCommand"
|
||||
|
||||
• **ctx**: `ButtonInteraction`\<`CacheType`\>
|
||||
|
||||
• **tbd**: [`SDT`](/v4/api/type-aliases/sdt/)
|
||||
• **tbd**: [`SDT`](/v4/api/interfaces/sdt/)
|
||||
|
||||
#### Returns
|
||||
|
||||
@@ -45,13 +45,93 @@ title: "ButtonCommand"
|
||||
|
||||
#### Source
|
||||
|
||||
[src/types/core-modules.ts:82](https://github.com/sern-handler/handler/blob/7c8e39defbafdd6312a04a2d30750d647a3ab22b/src/types/core-modules.ts#L82)
|
||||
[src/types/core-modules.ts:226](https://github.com/sern-handler/handler/blob/3f703c17b88b6add7de919772e7b2a7faffd3910/src/types/core-modules.ts#L226)
|
||||
|
||||
***
|
||||
|
||||
### locals
|
||||
|
||||
> **locals**: `Record`\<`string`, `unknown`\>
|
||||
> **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
|
||||
|
||||
```ts
|
||||
// In a plugin
|
||||
module.locals.registrationDate = Date.now();
|
||||
module.locals.version = "1.0.0";
|
||||
module.locals.permissions = ["ADMIN", "MODERATE"];
|
||||
```
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
// In module execution
|
||||
console.log(`Command registered on: ${new Date(module.locals.registrationDate)}`);
|
||||
```
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
// Storing localization data
|
||||
module.locals.translations = {
|
||||
en: "Hello",
|
||||
es: "Hola",
|
||||
fr: "Bonjour"
|
||||
};
|
||||
```
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
// Storing command metadata
|
||||
module.locals.metadata = {
|
||||
category: "admin",
|
||||
cooldown: 5000,
|
||||
requiresPermissions: true
|
||||
};
|
||||
```
|
||||
|
||||
#### 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:
|
||||
```typescript
|
||||
module.locals['myPlugin:data'] = value;
|
||||
```
|
||||
|
||||
2. Document the data structure you're storing:
|
||||
```typescript
|
||||
interface MyPluginData {
|
||||
version: string;
|
||||
timestamp: number;
|
||||
}
|
||||
module.locals['myPlugin:data'] = {
|
||||
version: '1.0.0',
|
||||
timestamp: Date.now()
|
||||
} as MyPluginData;
|
||||
```
|
||||
|
||||
3. Use type-safe accessors when possible:
|
||||
```typescript
|
||||
const getPluginData = (module: Module): MyPluginData =>
|
||||
module.locals['myPlugin:data'];
|
||||
```
|
||||
|
||||
#### Inherited from
|
||||
|
||||
@@ -59,7 +139,7 @@ title: "ButtonCommand"
|
||||
|
||||
#### Source
|
||||
|
||||
[src/types/core-modules.ts:44](https://github.com/sern-handler/handler/blob/7c8e39defbafdd6312a04a2d30750d647a3ab22b/src/types/core-modules.ts#L44)
|
||||
[src/types/core-modules.ts:195](https://github.com/sern-handler/handler/blob/3f703c17b88b6add7de919772e7b2a7faffd3910/src/types/core-modules.ts#L195)
|
||||
|
||||
***
|
||||
|
||||
@@ -81,7 +161,7 @@ title: "ButtonCommand"
|
||||
|
||||
#### Source
|
||||
|
||||
[src/types/core-modules.ts:40](https://github.com/sern-handler/handler/blob/7c8e39defbafdd6312a04a2d30750d647a3ab22b/src/types/core-modules.ts#L40)
|
||||
[src/types/core-modules.ts:123](https://github.com/sern-handler/handler/blob/3f703c17b88b6add7de919772e7b2a7faffd3910/src/types/core-modules.ts#L123)
|
||||
|
||||
***
|
||||
|
||||
@@ -95,7 +175,7 @@ title: "ButtonCommand"
|
||||
|
||||
#### Source
|
||||
|
||||
[src/types/core-modules.ts:36](https://github.com/sern-handler/handler/blob/7c8e39defbafdd6312a04a2d30750d647a3ab22b/src/types/core-modules.ts#L36)
|
||||
[src/types/core-modules.ts:119](https://github.com/sern-handler/handler/blob/3f703c17b88b6add7de919772e7b2a7faffd3910/src/types/core-modules.ts#L119)
|
||||
|
||||
***
|
||||
|
||||
@@ -109,7 +189,7 @@ title: "ButtonCommand"
|
||||
|
||||
#### Source
|
||||
|
||||
[src/types/core-modules.ts:37](https://github.com/sern-handler/handler/blob/7c8e39defbafdd6312a04a2d30750d647a3ab22b/src/types/core-modules.ts#L37)
|
||||
[src/types/core-modules.ts:120](https://github.com/sern-handler/handler/blob/3f703c17b88b6add7de919772e7b2a7faffd3910/src/types/core-modules.ts#L120)
|
||||
|
||||
***
|
||||
|
||||
@@ -123,7 +203,7 @@ title: "ButtonCommand"
|
||||
|
||||
#### Source
|
||||
|
||||
[src/types/core-modules.ts:38](https://github.com/sern-handler/handler/blob/7c8e39defbafdd6312a04a2d30750d647a3ab22b/src/types/core-modules.ts#L38)
|
||||
[src/types/core-modules.ts:121](https://github.com/sern-handler/handler/blob/3f703c17b88b6add7de919772e7b2a7faffd3910/src/types/core-modules.ts#L121)
|
||||
|
||||
***
|
||||
|
||||
@@ -137,4 +217,4 @@ title: "ButtonCommand"
|
||||
|
||||
#### Source
|
||||
|
||||
[src/types/core-modules.ts:81](https://github.com/sern-handler/handler/blob/7c8e39defbafdd6312a04a2d30750d647a3ab22b/src/types/core-modules.ts#L81)
|
||||
[src/types/core-modules.ts:225](https://github.com/sern-handler/handler/blob/3f703c17b88b6add7de919772e7b2a7faffd3910/src/types/core-modules.ts#L225)
|
||||
|
||||
Reference in New Issue
Block a user