1
- import { Client , Events , SlashCommandBuilder , Interaction , CommandInteraction , REST , Routes , InteractionType , ApplicationCommandType } from "discord.js" ;
2
-
3
- export interface Command {
4
- info : SlashCommandBuilder ,
5
- execute : ( interaction : CommandInteraction ) => Promise < void > ;
6
- }
1
+ import { Client } from "discord.js" ;
7
2
8
3
export interface IClient extends Client {
9
- commands : Map < string , Command > ;
10
- addCommand : ( command : Command ) => void ;
11
- saveCommands : ( ) => Promise < void > ;
12
4
/*
13
5
* Waits for client to be ready, if it is already ready it will immidiately resolve
14
6
*/
@@ -19,41 +11,9 @@ const client = new Client({
19
11
intents : [ "DirectMessages" ] ,
20
12
} ) as IClient ;
21
13
22
- const rest = new REST ( { version : "10" } ) ;
23
-
24
- client . commands = new Map < string , Command > ( ) ;
25
- client . addCommand = ( command : Command ) => {
26
- client . commands . set ( command . info . name , command ) ;
27
- } ;
28
- client . saveCommands = async ( ) => {
29
- const commands = [ ] ;
30
- for ( const [ _ , command ] of client . commands . entries ( ) ) {
31
- commands . push ( command . info . toJSON ( ) ) ;
32
- }
33
- await rest . put ( Routes . applicationGuildCommands ( process . env . DISCORD_APPLICATION_ID ! , process . env . DISCORD_GUILD_ID ! ) , {
34
- body : commands
35
- } ) ;
36
- } ;
37
-
38
- rest . setToken ( process . env . DISCORD_TOKEN ! ) ;
39
14
client . login ( process . env . DISCORD_TOKEN ) ;
40
15
client . user ?. setStatus ( "online" ) ;
41
16
42
- client . on ( "interactionCreateHook" , ( interaction : Interaction ) => {
43
- if ( ! interaction . isChatInputCommand ( ) ) return ;
44
-
45
- const command = client . commands . get ( interaction . commandName ) ;
46
- if ( ! command ) {
47
- interaction . reply ( {
48
- content : "Command does not exist" ,
49
- ephemeral : true
50
- } ) ;
51
- return ;
52
- } ;
53
-
54
- command . execute ( interaction ) ;
55
- } ) ;
56
-
57
17
client . awaitReady = async function ( ) {
58
18
const isReady = this . isReady ( ) ;
59
19
if ( isReady ) return ;
0 commit comments