File tree Expand file tree Collapse file tree 1 file changed +21
-12
lines changed Expand file tree Collapse file tree 1 file changed +21
-12
lines changed Original file line number Diff line number Diff line change @@ -2,24 +2,33 @@ const Discord = require('discord.js');
2
2
const bot = new Discord . Client ( ) ;
3
3
require ( 'dotenv' ) . config ( ) ;
4
4
5
- const PREFIX = 'DG!' ;
5
+
6
+ const RoboCommands = ( msg ) => ( {
7
+ "website" : ( ) => msg . reply ( 'https://www.da-developers.dev' ) ,
8
+ "bot info" : ( ) => msg . reply ( 'Version 1.0.1' )
9
+ } ) ;
6
10
7
11
/**
8
12
* Handles incoming messages for Robo
9
13
*/
10
14
const handleMessage = ( msg ) => {
11
- let args = msg . content . substring ( PREFIX . length ) . split ( " " ) ;
12
- const {
13
- sendMessage
14
- } = msg . channel ;
15
- switch ( args [ 0 ] ) {
16
- case 'website' :
17
- sendMessage ( 'da-developers.dev' ) ;
18
- break ;
19
- case 'info' :
20
- ( args [ 1 ] === 'version' ) ? sendMessage ( 'Version 1.0.1' ) : sendMessage ( 'Invalid args' )
21
- break ;
15
+ const PREFIX = 'DG!' ;
16
+ const msgs = msg . content . split ( " " )
17
+ const roboCommands = RoboCommands ( msg ) ;
18
+ if ( msgs [ 0 ] == PREFIX ) {
19
+ // getting rid of DG! prefix
20
+ msgs . splice ( 0 , 1 ) ;
21
+ if ( msgs . length === 0 || msgs == undefined ) {
22
+ msg . reply ( 'At least one argument is needed to complete a task.' ) ;
23
+ } else {
24
+ if ( roboCommands [ msgs . join ( " " ) ] ) {
25
+ roboCommands [ msgs . join ( " " ) ] ( ) ;
26
+ } else {
27
+ msg . reply ( 'The command you entered is could not be found.' )
28
+ }
29
+ }
22
30
}
31
+
23
32
}
24
33
25
34
bot . on ( 'ready' , ( ) => console . log ( 'Robo is on.' ) )
You can’t perform that action at this time.
0 commit comments