@@ -7,6 +7,7 @@ import { defaultConfig } from "./constants.js";
77import { handleGameResend , onButtonPress , onModalSubmit , onSelectMenu } from "./gameLogic/index.js" ;
88import { patch } from "./patchContext.js" ;
99import { Command , Config } from "./types.js" ;
10+ import { onMsgError } from "./utils.js" ;
1011
1112declare global {
1213 interface Array < T > {
@@ -64,18 +65,28 @@ client.on("messageCreate", msg => {
6465 if ( ! msg . content . startsWith ( prefix ) ) return ;
6566 const args = msg . content . slice ( prefix . length ) . split ( / + / ) ;
6667 const command = args . shift ( ) ;
67- if ( commands [ command ] ) commands [ command ] . execute ( msg , args ) ;
68+ if ( commands [ command ] ) {
69+ try {
70+ commands [ command ] . execute ( msg , args ) ;
71+ } catch ( e ) {
72+ onMsgError ( e , msg ) ;
73+ }
74+ }
6875} ) ;
6976
7077client . on ( "interactionCreate" , ctx => {
7178 patch ( ctx ) ;
7279
73- if ( ctx . type === InteractionTypes . MESSAGE_COMPONENT ) {
74- if ( ctx . isButtonComponentInteraction ( ) ) onButtonPress ( ctx ) ;
75- else onSelectMenu ( ctx ) ;
76- }
77- else if ( ctx . type === InteractionTypes . MODAL_SUBMIT ) {
78- onModalSubmit ( ctx ) ;
80+ try {
81+ if ( ctx . type === InteractionTypes . MESSAGE_COMPONENT ) {
82+ if ( ctx . isButtonComponentInteraction ( ) ) onButtonPress ( ctx ) ;
83+ else onSelectMenu ( ctx ) ;
84+ }
85+ else if ( ctx . type === InteractionTypes . MODAL_SUBMIT ) {
86+ onModalSubmit ( ctx ) ;
87+ }
88+ } catch ( e ) {
89+ onMsgError ( e , ctx ) ;
7990 }
8091} ) ;
8192
0 commit comments