To use DiscordHono in a runtime like Cloudflare Workers, mount the .fetch method to your worker's entry point.
- GET requests: The
.fetch method automatically responds with Operational🔥 for health checks. - POST requests: The method handles signature verification using
DISCORD_PUBLIC_KEY and routes the interaction to the appropriate handler based on the interaction type and custom_id or command name. - Error Handling: If a handler is missing for a valid interaction, it throws a
handler error (resulting in a 500 response). If signature verification fails, it returns a 401 response.
// Example Cloudflare Worker entry point
export default {
fetch: (request, env, ctx) => app.fetch(request, env, ctx),
scheduled: (event, env, ctx) => app.scheduled(event, env, ctx),
};