1
- function isFunction ( object ) {
2
- return typeof object === 'function' ;
3
- }
4
-
5
1
/**
6
2
* Commands wrapper
7
3
* @param {object } commands - Object that contains the commands.
@@ -17,12 +13,8 @@ class Commands {
17
13
* @param {string } name - Command's name.
18
14
* @param {function } callback - Callback to command.
19
15
*/
20
- set ( name , callback ) {
21
- if ( ! isFunction ( callback ) ) {
22
- throw new Error ( `${ callback } must be a function` ) ;
23
- }
24
-
25
- this . commands [ name ] = callback ;
16
+ register ( cmd ) {
17
+ this . commands [ cmd . name ] = cmd ;
26
18
}
27
19
28
20
/**
@@ -48,15 +40,15 @@ class Commands {
48
40
* @see https://docs.wwebjs.dev/Message.html
49
41
* @see https://docs.wwebjs.dev/Client.html
50
42
*/
51
- async call ( cmd , data , message , client ) {
52
- if ( ! this . has ( cmd ) ) {
53
- throw new Error ( `${ cmd } is not registered` ) ;
43
+ async call ( cmdName , data , message , client ) {
44
+ if ( ! this . has ( cmdName ) ) {
45
+ throw new Error ( `${ cmdName } is not registered. ` ) ;
54
46
}
55
47
56
- const response = await this . commands [ cmd ] ( data , message , client ) ;
57
-
58
- if ( response ) {
59
- message . reply ( String ( response ) ) ;
48
+ try {
49
+ await this . commands [ cmdName ] . execute ( data , message , client ) ;
50
+ } catch ( e ) {
51
+ message . reply ( `❗ ${ e . message } ` ) ;
60
52
}
61
53
}
62
54
}
0 commit comments