Skip to content

Shardlens

Defined in: packages/discordjs/src/index.ts:97

What createShardlens returns. Its methods never throw; wrapped handlers re-throw only their own errors.

readonly client: ShardlensClient

Defined in: packages/discordjs/src/index.ts:159

The underlying transport from @shardlens/core, for adapters and tools built on this one.

flush(): Promise<void>

Defined in: packages/discordjs/src/index.ts:150

Sends what is queued now instead of at the next interval. Never throws.

Promise<void>


forgetUser(userId): Promise<{ erased: number; } | undefined>

Defined in: packages/discordjs/src/index.ts:143

Deletes what the collector stored about a user (right to erasure): in privacy mode, the rows under the hashes this bot can still compute, which are those of the current salt period and the previous one; in audit mode, every period whose salt still exists. Does not opt them out of future collection; call Shardlens.optOut as well if they asked for that. Never throws.

string

Promise<{ erased: number; } | undefined>


handlerFinished(interaction, result?): void

Defined in: packages/discordjs/src/index.ts:116

Call when a handler started with Shardlens.handlerStarted has finished or thrown.

BaseInteraction

HandlerResult

void


handlerStarted(interaction): void

Defined in: packages/discordjs/src/index.ts:114

For frameworks that run handlers themselves and announce it (Sapphire’s chatInputCommandRun, for example): call when the handler starts. With Shardlens.handlerFinished it records what Shardlens.wrap would.

BaseInteraction

void


isOptedOut(userId): boolean

Defined in: packages/discordjs/src/index.ts:136

Whether Shardlens.optOut (or the optedOut option) covers this user in this process.

string

boolean


on(event, listener): () => void

Defined in: packages/discordjs/src/index.ts:148

Listens for failures the SDK caught and counted, named by where they happened ('flush', 'interactionCreate', 'onOptOutChange'…). Returns a function that removes the listener.

"error"

(name, error) => void

() => void


optIn(userId): void

Defined in: packages/discordjs/src/index.ts:134

Reverses Shardlens.optOut.

string

void


optOut(userId): void

Defined in: packages/discordjs/src/index.ts:132

Stops recording a user’s interactions in this process (for example from a /privacy optout command).

string

void


shutdown(options?): Promise<void>

Defined in: packages/discordjs/src/index.ts:155

Removes all hooks and flushes, giving up after timeoutMs (default 2,000). A second call, such as SIGTERM from a shard manager after SIGINT from the terminal, waits for the same flush. The SDK never handles signals.

number

Promise<void>


stats(): ShardlensStats

Defined in: packages/discordjs/src/index.ts:157

Queue depth, drops by reason, failed sends and caught errors, for your own health checks.

ShardlensStats


track<N>(name, props?, context?): void

Defined in: packages/discordjs/src/index.ts:102

Records a custom event. Names are lower snake case; properties are limited to 2 KB of strings, numbers, booleans and nulls. Invalid events are dropped and counted, never thrown.

N extends string

N

CustomEventProps<N>

TrackContext

void


trackMessageCommand(message, run): void

Defined in: packages/discordjs/src/index.ts:122

Records a command run from a message, such as a prefix command (!ban @user), after your bot’s parser matched it. Pass the command’s own name, not what was typed: message content is never read. Counted with interactions on the dashboard. Invalid runs are dropped and counted, never thrown.

Message

MessageCommandRun

void


wrap<A, R>(handler): (…args) => Promise<Awaited<R>>

Defined in: packages/discordjs/src/index.ts:107

Wraps an interaction handler to record its duration and failures. The handler’s errors are re-thrown unchanged, so your own error handling still runs.

A extends [BaseInteraction<CacheType>, ...unknown[]]

R

(…args) => R | Promise<R>

(…args) => Promise<Awaited<R>>


wrapMessageCommand<A, R>(command, handler): (…args) => Promise<Awaited<R>>

Defined in: packages/discordjs/src/index.ts:127

Wraps a message command handler to record its duration and failures, like Shardlens.wrap does for interactions. The handler’s errors are re-thrown unchanged.

A extends [Message<boolean>, ...unknown[]]

R

string | MessageCommandInfo

(…args) => R | Promise<R>

(…args) => Promise<Awaited<R>>