1
+ require ( 'dotenv' ) . config ( ) ;
2
+ const { Client, Events, GatewayIntentBits } = require ( 'discord.js' ) ;
3
+ const startServer = require ( './aternos_functions/startServer' ) ;
4
+ const checkStatus = require ( './aternos_functions/checkServerStatus' ) ;
5
+ const stopServer = require ( './aternos_functions/stopServer' ) ;
6
+ const restartServer = require ( './aternos_functions/restartServer' ) ;
7
+ const checkAccess = require ( './utils/checkAccess' ) ;
8
+ const token = process . env . BOT_TOKEN ;
9
+ const client = new Client ( { intents : [ GatewayIntentBits . Guilds ] } ) ;
10
+ client . login ( token ) ;
11
+
12
+ client . once ( Events . ClientReady , ( c ) => {
13
+ console . log ( `Ready! Logged in as ${ c . user . tag } ` ) ;
14
+ } ) ;
15
+
16
+ client . on ( Events . InteractionCreate , async ( interaction ) => {
17
+ if ( ! interaction . isChatInputCommand ( ) ) return ;
18
+ try {
19
+ switch ( interaction . commandName ) {
20
+ case 'check-status' :
21
+ await interaction . deferReply ( ) ;
22
+ let status = await checkStatus ( ) ;
23
+ await interaction . editReply ( `current status : ${ status } ` ) ;
24
+ break ;
25
+ case 'start-server' :
26
+ if ( ! checkAccess ( interaction . member . roles . cache , 'start' ) )
27
+ return await interaction . reply ( "you don't have access" ) ;
28
+ await interaction . deferReply ( ) ;
29
+ let start = await startServer ( ) ;
30
+ await interaction . editReply ( start ) ;
31
+ break ;
32
+ case 'stop-server' :
33
+ if ( ! checkAccess ( interaction . member . roles . cache , 'stop' ) )
34
+ return await interaction . reply ( "you don't have access" ) ;
35
+ await interaction . deferReply ( ) ;
36
+ let stop = await stopServer ( ) ;
37
+ await interaction . editReply ( stop ) ;
38
+ break ;
39
+ case 'restart-server' :
40
+ if ( ! checkAccess ( interaction . member . roles . cache , 'restart' ) )
41
+ return await interaction . reply ( "you don't have access" ) ;
42
+ await interaction . deferReply ( ) ;
43
+ let restart = await restartServer ( ) ;
44
+ await interaction . editReply ( restart ) ;
45
+ break ;
46
+ default :
47
+ break ;
48
+ }
49
+ } catch ( error ) {
50
+ await interaction . reply ( 'sorry but something went wrong' ) ;
51
+ console . log ( error ) ;
52
+ }
53
+ } ) ;
0 commit comments