create-discord-bot
Version:
A simple way to create a startup Discord bot.
41 lines (37 loc) • 1.03 kB
text/typescript
import type { ClientEvents } from 'npm:discord.js@^14.20.0';
import { z } from 'npm:zod@^3.24.1';
import type { StructurePredicate } from '../util/loaders.ts';
/**
* Defines the structure of an event.
*/
export type Event<T extends keyof ClientEvents = keyof ClientEvents> = {
/**
* The function to execute when the event is emitted.
*
* @param parameters - The parameters of the event
*/
execute(...parameters: ClientEvents[T]): Promise<void> | void;
/**
* The name of the event to listen to
*/
name: T;
/**
* Whether or not the event should only be listened to once
*
* @defaultValue false
*/
once?: boolean;
};
/**
* Defines the schema for an event.
*/
export const schema = z.object({
name: z.string(),
once: z.boolean().optional().default(false),
execute: z.function(),
});
/**
* Defines the predicate to check if an object is a valid Event type.
*/
export const predicate: StructurePredicate<Event> = (structure: unknown): structure is Event =>
schema.safeParse(structure).success;