1- function isFunction ( object ) {
2- return typeof object === 'function' ;
3- }
4-
51/**
62 * Commands wrapper
73 * @param {object } commands - Object that contains the commands.
@@ -17,12 +13,8 @@ class Commands {
1713 * @param {string } name - Command's name.
1814 * @param {function } callback - Callback to command.
1915 */
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 ;
2618 }
2719
2820 /**
@@ -48,15 +40,15 @@ class Commands {
4840 * @see https://docs.wwebjs.dev/Message.html
4941 * @see https://docs.wwebjs.dev/Client.html
5042 */
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. ` ) ;
5446 }
5547
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 } ` ) ;
6052 }
6153 }
6254}
0 commit comments