import { APIChatInputApplicationCommandInteraction, InteractionResponseType } from 'discord-api-types/v10'; import { env } from '../types/env.js'; import { ExecutionContext } from '@cloudflare/workers-types'; import { command } from '../types/command.js'; export async function handleCommand( interaction: APIChatInputApplicationCommandInteraction, env: env, ctx: ExecutionContext, commands: Record ) { const command = commands[interaction.data.name]; if (!command) { return new Response(JSON.stringify({ type: InteractionResponseType.ChannelMessageWithSource, data: { flags: 64, content: "I could not find this command" } }), { headers: { 'Content-Type': 'application/json' } }); } return command.handle({ interaction, env, wait: ctx.waitUntil.bind(ctx), response: (data: any) => new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json' } }) }); }