/
index.ts
27 lines (25 loc) · 872 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
import type { RESTPostAPIApplicationCommandsJSONBody, CommandInteraction } from 'npm:discord.js@^14.14.0';
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> | void;
};
// Defines the predicate to check if an object is a valid Command type
export const predicate: StructurePredicate<Command> = (structure): structure is Command =>
Boolean(structure) &&
typeof structure === 'object' &&
'data' in structure! &&
'execute' in structure &&
typeof structure.data === 'object' &&
typeof structure.execute === 'function';