Honocord
Constructor
Section titled “Constructor”new Honocord(options?: { isCFWorker?: boolean; debugRest?: boolean; cacheTtlMs?: number;})isCFWorker?: boolean— enable Cloudflare Workers async processing (also detected via envc.env.IS_CF_WORKER === "true").debugRest?: boolean— enable REST debug listeners to log requests/responses.cacheTtlMs?: number— default TTL in milliseconds for cached entities when a cache adapter is registered viawithCache. Set0to disable expiration.
Public methods
Section titled “Public methods”loadHandlers(...handlers: FlatOrNestedArray<AnyHandler>): void
Section titled “loadHandlers(...handlers: FlatOrNestedArray<AnyHandler>): void”Register Slash/Context/Component/Modal/WebhookEvent handlers. Accepts flat or nested arrays. Guild-scoped command handlers are registered under guildId:commandName.
use<Context extends BaseInteractionContext = BaseInteractionContext>(...middleware: MiddlewareFunction<Context>[]): this
Section titled “use<Context extends BaseInteractionContext = BaseInteractionContext>(...middleware: MiddlewareFunction<Context>[]): this”Register middleware functions that run in-order before handlers. Middleware signature: async (c, next) => Promise<void>. Use c.get/c.set to share data.
clearMiddleware(): this
Section titled “clearMiddleware(): this”Remove all registered middleware.
interactionsHandler: (c: BaseInteractionContext) => Promise<Response | void>
Section titled “interactionsHandler: (c: BaseInteractionContext) => Promise<Response | void>”Hono-compatible POST handler for interactions. Verifies requests, replies to Ping interactions, and dispatches other interaction types. If running on CF Workers, processing is deferred via c.executionCtx.waitUntil (returns 202). Synchronous mode returns a 500 on unhandled exceptions.
webhookHandler: (c: Context) => Promise<Response>
Section titled “webhookHandler: (c: Context) => Promise<Response>”Hono-compatible POST handler for Discord webhook events. Verifies the request signature, routes to the matching WebhookEventHandler by event type, and returns 404 if no handler is found. On CF Workers, event processing is deferred via waitUntil.
getApp(options?: { interactionsPath?: string; webhookPath?: string }): Hono<{ Variables: BaseVariables }>
Section titled “getApp(options?: { interactionsPath?: string; webhookPath?: string }): Hono<{ Variables: BaseVariables }>”Returns a Hono application with a health GET on all routes, the interactions POST mounted at / and options.interactionsPath (default /interactions) when command handlers are registered, and the webhook POST at options.webhookPath (default /webhook) when webhook handlers are registered.
withCache<TheEnv>(factory: (env: TheEnv) => BaseCacheAdapter): this
Section titled “withCache<TheEnv>(factory: (env: TheEnv) => BaseCacheAdapter): this”Registers a cache adapter factory. The factory receives the request environment and returns a BaseCacheAdapter instance. Called once per unique environment on first use.
See Caching for details on how caching works and how to implement a cache adapter.
Runtime notes
Section titled “Runtime notes”- Requests are verified using the configured public key; invalid signatures receive 401.
- For CF Workers use
c.executionCtx.waitUntilto offload processing and return 202 immediately. - When
debugRestis enabled the internal REST client logs request/response details to aid troubleshooting. - Channels resolved from interaction payloads are not cached — Discord only provides partial objects with
idandtype. - The guild object on interactions is also partial (
id,features,locale) and is not cached.