Skip to main content

@sapphire/pieces

Namespaces

Enumerations

Classes

Interfaces

Type aliases

AsyncPreloadResult

ฦฌ AsyncPreloadResult<T>: Promise<Constructor<T> & Record<PropertyKey, unknown>>

Represents the return data from ILoaderStrategy.preload

Type parameters

NameType
Textends Piece

Defined in

projects/pieces/src/lib/strategies/ILoaderStrategy.ts:48


FilterResult

ฦฌ FilterResult: ModuleData | null

The result from the filter.

Defined in

projects/pieces/src/lib/strategies/ILoaderStrategy.ts:38


ILoaderResult

ฦฌ ILoaderResult<T>: AsyncIterableIterator<ILoaderResultEntry<T>>

Represents the return data from ILoaderStrategy.load.

Type parameters

NameType
Textends Piece

Defined in

projects/pieces/src/lib/strategies/ILoaderStrategy.ts:58


ILoaderResultEntry

ฦฌ ILoaderResultEntry<T>: Ctor<ConstructorParameters<typeof Piece>, T>

Represents an entry from ILoaderResult.

Type parameters

NameType
Textends Piece

Defined in

projects/pieces/src/lib/strategies/ILoaderStrategy.ts:53


PreloadResult

ฦฌ PreloadResult<T>: Awaitable<Constructor<T> & Record<PropertyKey, unknown>>

Represents the return data from ILoaderStrategy.preload

Type parameters

NameType
Textends Piece

Defined in

projects/pieces/src/lib/strategies/ILoaderStrategy.ts:43

Variables

container

โ€ข container: Container

The injected variables that will be accessible to any place. To add an extra property, simply add a property with a regular assignment, and it will be available in all places simultaneously.

example

// Add a reference to the Client:
import { container } from '@sapphire/pieces';

export class SapphireClient extends Client {
constructor(options) {
super(options);

container.client = this;
}
}

// Can be placed anywhere in a TypeScript file, for JavaScript projects,
// you can create an `augments.d.ts` and place the code there.
declare module '@sapphire/pieces' {
interface Container {
client: SapphireClient;
}
}

// In any piece, core, plugin, or custom:
export class UserCommand extends Command {
public run(message, args) {
// The injected client is available here:
const { client } = this.container;

// ...
}
}

example

// In a plugin's context, e.g. API:
class Api extends Plugin {
static [postInitialization]() {
const server = new Server(this);
container.server = server;

// ...
}
}

declare module '@sapphire/pieces' {
interface Container {
server: Server;
}
}

// In any piece, even those that aren't routes nor middlewares:
export class UserRoute extends Route {
public [methods.POST](message, args) {
// The injected server is available here:
const { server } = this.container;

// ...
}
}

Defined in

projects/pieces/src/lib/shared/Container.ts:84

Functions

getRootData

โ–ธ getRootData(): RootData

Returns

RootData

Defined in

projects/pieces/src/lib/internal/RootScan.ts:5