Honocord
Class: Honocord
Section titled “Class: Honocord”Defined in: Honocord.ts:86
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Honocord(
__namedParameters?):Honocord
Defined in: Honocord.ts:138
Parameters
Section titled “Parameters”__namedParameters?
Section titled “__namedParameters?”HonocordOptions = {}
Returns
Section titled “Returns”Honocord
Methods
Section titled “Methods”clearMiddleware()
Section titled “clearMiddleware()”clearMiddleware():
this
Defined in: Honocord.ts:769
Clears all registered middleware functions.
Returns
Section titled “Returns”this
The Honocord instance for chaining.
getApp()
Section titled “getApp()”getApp(
options?):Hono<{Variables:BaseVariables; },BlankSchema,"/">
Defined in: Honocord.ts:608
Returns a Hono App instance with the interaction handler mounted at the root path and a GET Handler for all paths, which returns a simple Health response.
Parameters
Section titled “Parameters”options?
Section titled “options?”HonocordAppOptions = {}
Returns
Section titled “Returns”Hono<{ Variables: BaseVariables; }, BlankSchema, "/">
Example
Section titled “Example”import { Honocord } from "honocord";
const honoCord = new Honocord();
export default honoCord.getApp();// Supports both "/" and "/interactions" for the interactions handler, if any are loaded// And `/webhook` for the webhook handler if any are loadedinteractionsHandler()
Section titled “interactionsHandler()”interactionsHandler(
c):Promise<Response&TypedResponse<"Bad request signature.",401,"text"> |Response&TypedResponse<"No interaction found.",400,"text"> |JSONRespondReturn<{ },202> |Response&TypedResponse<"Internal server error.",500,"text"> |JSONRespondReturn<{type:InteractionResponseType; },ContentfulStatusCode> |undefined>
Defined in: Honocord.ts:551
Returns a Hono handler for POST Requests handling Discord interactions.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<Response & TypedResponse<"Bad request signature.", 401, "text"> | Response & TypedResponse<"No interaction found.", 400, "text"> | JSONRespondReturn<{ }, 202> | Response & TypedResponse<"Internal server error.", 500, "text"> | JSONRespondReturn<{ type: InteractionResponseType; }, ContentfulStatusCode> | undefined>
Example
Section titled “Example”import { Hono } from "hono";import { Honocord } from "honocord";
const app = new Hono();const bot = new Honocord();
app.get("/", (c) => c.text("🔥 Honocord is running!"));app.post("/interactions", bot.interactionsHandler);
export default app;loadHandlers()
Section titled “loadHandlers()”loadHandlers(…
handlers):void
Defined in: Honocord.ts:150
Registers handlers for interactions.
Parameters
Section titled “Parameters”handlers
Section titled “handlers”…FlatOrNestedArray<AnyHandler>
Array of CommandHandler, ComponentHandler, or ModalHandler instances
For an example of usage, see the Example Repository.
Returns
Section titled “Returns”void
use<
Context>(…middleware):this
Defined in: Honocord.ts:660
Registers a middleware function to process interaction contexts.
Middleware receives the Hono context and a next callback:
- Access/modify context variables via
c.get()andc.set() - Access the interaction object via
c.var.command,c.var.component,c.var.modal, orc.var.autocomplete - Access environment bindings via
c.env - Call
await next()to continue to the next middleware or handler
The context is passed by reference, so all modifications persist through the middleware chain and into handlers.
Type Parameters
Section titled “Type Parameters”Context
Section titled “Context”Context extends BaseInteractionContext = BaseInteractionContext
Parameters
Section titled “Parameters”middleware
Section titled “middleware”…MiddlewareFunction<Context>[]
The middleware function(s) to register.
Returns
Section titled “Returns”this
The Honocord instance for chaining.
Example
Section titled “Example”bot.use(async (c, next) => { // Set custom data in context c.set('startTime', Date.now());
// Continue to next middleware/handler // you can also return next() directly if no post-processing is needed await next();
// Code here runs after the handler completes console.log('Duration:', Date.now() - c.get('startTime'));});webhookHandler()
Section titled “webhookHandler()”webhookHandler(
c):Promise<any>
Defined in: Honocord.ts:684
Returns a Hono handler for POST requests handling Discord webhook events.
On Cloudflare Workers, webhook events are processed asynchronously using waitUntil,
allowing immediate response to Discord while extending the worker’s lifetime to complete processing.
Parameters
Section titled “Parameters”Context
Returns
Section titled “Returns”Promise<any>
Example
Section titled “Example”import { Hono } from "hono";import { Honocord } from "honocord";
const app = new Hono();const bot = new Honocord();
app.post("/webhook", bot.webhookHandler);
export default app;withCache()
Section titled “withCache()”withCache<
TheEnv>(factory):this
Defined in: Honocord.ts:746
Registers a cache adapter factory for use throughout the bot.
The factory receives the request environment and returns a BaseCacheAdapter instance.
On Cloudflare Workers, use DurableObjectCacheAdapter.
On self-hosted environments, use MemoryCacheAdapter, MongoCacheAdapter, or RedisAdapter.
Type Parameters
Section titled “Type Parameters”TheEnv
Section titled “TheEnv”TheEnv = any
Parameters
Section titled “Parameters”factory
Section titled “factory”(env) => BaseCacheAdapter
A function that receives the environment and returns a cache adapter.
Returns
Section titled “Returns”this
The Honocord instance for chaining.
Example
Section titled “Example”// Cloudflare Workersbot.withCache((env) => new DurableObjectCacheAdapter(env.MY_CACHE));
// Self-hosted (pre-initialized)const cache = new MongoCacheAdapter(process.env.MONGO_URI!);await cache.connect();bot.withCache(() => cache);