import type { CommandInteraction, RESTPostAPIApplicationCommandsJSONBody } from 'discord.js'; import { z } from 'zod'; import type { StructurePredicate } from '../util/loaders.ts'; /** * Defines the structure of a command */ export type Command = { /** * The data for the command */ data: RESTPostAPIApplicationCommandsJSONBody; /** * The function to execute when the command is called * * @param interaction - The interaction of the command */ execute(interaction: CommandInteraction): Promise | void; }; /** * Defines the schema for a command */ export const schema = z.object({ data: z.record(z.any()), execute: z.function(), }); /** * Defines the predicate to check if an object is a valid Command type. */ export const predicate: StructurePredicate = (structure): structure is Command => schema.safeParse(structure).success;