/
index.ts
33 lines (31 loc) · 954 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type { ClientEvents } from 'npm:discord.js@^14.14.0';
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 predicate to check if an object is a valid Event type.
export const predicate: StructurePredicate<Event> = (structure): structure is Event =>
Boolean(structure) &&
typeof structure === 'object' &&
'name' in structure! &&
'execute' in structure &&
typeof structure.name === 'string' &&
typeof structure.execute === 'function';