Shardlens
Defined in: packages/discordjs/src/index.ts:97
What createShardlens returns. Its methods never throw; wrapped handlers re-throw only their own errors.
Properties
Section titled “Properties”client
Section titled “client”
readonlyclient:ShardlensClient
Defined in: packages/discordjs/src/index.ts:159
The underlying transport from @shardlens/core, for adapters and tools built on this one.
Methods
Section titled “Methods”flush()
Section titled “flush()”flush():
Promise<void>
Defined in: packages/discordjs/src/index.ts:150
Sends what is queued now instead of at the next interval. Never throws.
Returns
Section titled “Returns”Promise<void>
forgetUser()
Section titled “forgetUser()”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.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”Promise<{ erased: number; } | undefined>
handlerFinished()
Section titled “handlerFinished()”handlerFinished(
interaction,result?):void
Defined in: packages/discordjs/src/index.ts:116
Call when a handler started with Shardlens.handlerStarted has finished or thrown.
Parameters
Section titled “Parameters”interaction
Section titled “interaction”BaseInteraction
result?
Section titled “result?”Returns
Section titled “Returns”void
handlerStarted()
Section titled “handlerStarted()”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.
Parameters
Section titled “Parameters”interaction
Section titled “interaction”BaseInteraction
Returns
Section titled “Returns”void
isOptedOut()
Section titled “isOptedOut()”isOptedOut(
userId):boolean
Defined in: packages/discordjs/src/index.ts:136
Whether Shardlens.optOut (or the optedOut option) covers this user in this process.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”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.
Parameters
Section titled “Parameters”"error"
listener
Section titled “listener”(name, error) => void
Returns
Section titled “Returns”() => void
optIn()
Section titled “optIn()”optIn(
userId):void
Defined in: packages/discordjs/src/index.ts:134
Reverses Shardlens.optOut.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”void
optOut()
Section titled “optOut()”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).
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”void
shutdown()
Section titled “shutdown()”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.
Parameters
Section titled “Parameters”options?
Section titled “options?”timeoutMs?
Section titled “timeoutMs?”number
Returns
Section titled “Returns”Promise<void>
stats()
Section titled “stats()”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.
Returns
Section titled “Returns”track()
Section titled “track()”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.
Type Parameters
Section titled “Type Parameters”N extends string
Parameters
Section titled “Parameters”N
props?
Section titled “props?”CustomEventProps<N>
context?
Section titled “context?”Returns
Section titled “Returns”void
trackMessageCommand()
Section titled “trackMessageCommand()”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.
Parameters
Section titled “Parameters”message
Section titled “message”Message
Returns
Section titled “Returns”void
wrap()
Section titled “wrap()”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.
Type Parameters
Section titled “Type Parameters”A extends [BaseInteraction<CacheType>, ...unknown[]]
R
Parameters
Section titled “Parameters”handler
Section titled “handler”(…args) => R | Promise<R>
Returns
Section titled “Returns”(…args) => Promise<Awaited<R>>
wrapMessageCommand()
Section titled “wrapMessageCommand()”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.
Type Parameters
Section titled “Type Parameters”A extends [Message<boolean>, ...unknown[]]
R
Parameters
Section titled “Parameters”command
Section titled “command”string | MessageCommandInfo
handler
Section titled “handler”(…args) => R | Promise<R>
Returns
Section titled “Returns”(…args) => Promise<Awaited<R>>