ShardlensHttp
Defined in: packages/http/src/index.ts:90
Methods
Section titled “Methods”flush()
Section titled “flush()”flush():
Promise<void>
Defined in: packages/http/src/index.ts:123
Waits for hashing to finish, then sends queued events. A wrapped handler given a waitUntil does this itself;
use it on a platform without one, before you return.
Returns
Section titled “Returns”Promise<void>
forgetUser()
Section titled “forgetUser()”forgetUser(
userId):Promise<{erased:number; } |undefined>
Defined in: packages/http/src/index.ts:118
Deletes everything the collector stored about a user. Never throws.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”Promise<{ erased: number; } | undefined>
isOptedOut()
Section titled “isOptedOut()”isOptedOut(
userId):boolean
Defined in: packages/http/src/index.ts:116
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”boolean
on(
event,listener): () =>void
Defined in: packages/http/src/index.ts:129
Listens for the SDK’s internal errors (tokens and request bodies removed). Returns a function that unsubscribes.
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/http/src/index.ts:115
Records this user’s events again.
Parameters
Section titled “Parameters”userId
Section titled “userId”string
Returns
Section titled “Returns”void
optOut()
Section titled “optOut()”optOut(
userId):void
Defined in: packages/http/src/index.ts:113
Drops this user’s events from now on (for example after /privacy opt-out). Persist the choice yourself.
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/http/src/index.ts:125
Sends what is queued and stops. Call it when a long-running server stops; Workers don’t need it.
Parameters
Section titled “Parameters”options?
Section titled “options?”timeoutMs?
Section titled “timeoutMs?”number
Returns
Section titled “Returns”Promise<void>
stats()
Section titled “stats()”stats():
ClientStats
Defined in: packages/http/src/index.ts:127
The SDK’s own health: queue depth, drops and internal errors.
Returns
Section titled “Returns”ClientStats
track()
Section titled “track()”track<
N>(name,props?,context?,waitUntil?):void
Defined in: packages/http/src/index.ts:106
Records a custom event. Invalid events are dropped and counted, never thrown. On serverless runtimes pass the
request’s ctx as waitUntil, or the event waits for the next interaction.
Type Parameters
Section titled “Type Parameters”N extends string
Parameters
Section titled “Parameters”N
props?
Section titled “props?”CustomEventProps<N>
context?
Section titled “context?”waitUntil?
Section titled “waitUntil?”Returns
Section titled “Returns”void
wrapInteractionHandler()
Section titled “wrapInteractionHandler()”wrapInteractionHandler<
I,A,R>(handler): (interaction, …args) =>Promise<Awaited<R>>
Defined in: packages/http/src/index.ts:99
Wraps the function that answers an interaction. The wrapped function records the interaction, how long your
response took against Discord’s 3-second deadline, and any error (re-thrown unchanged). Return the interaction
response body (or a Response) from your handler as usual.
If any argument has a waitUntil method (a Workers ExecutionContext, for example), events are sent through it
after your response, so the runtime doesn’t stop before they leave. PING interactions are not recorded.
Type Parameters
Section titled “Type Parameters”I extends RawInteraction
A extends unknown[]
R
Parameters
Section titled “Parameters”handler
Section titled “handler”(interaction, …args) => R | Promise<R>
Returns
Section titled “Returns”(interaction, …args) => Promise<Awaited<R>>