@@ -58,8 +58,10 @@ export function loadCommands(context: MyContext) {
5858 } ) ;
5959}
6060async function commandInteractionHandler ( context : MyContext , interaction : CommandInteraction ) {
61+ await interaction . deferReply ( { ephemeral : true } ) . catch ( console . error ) ;
62+
6163 const command = context . commands . get ( interaction . commandName ) ;
62- if ( ! command ) return interaction . reply ( { content : "Command not found" , ephemeral : true } ) ;
64+ if ( ! command ) return interaction . editReply ( { content : "Command not found" } ) . catch ( console . error ) ;
6365
6466 if ( commandPermissionCheck ( interaction , command ) ) return ;
6567 if ( commandCooldownCheck ( interaction , command , context ) ) return ;
@@ -68,15 +70,13 @@ async function commandInteractionHandler(context: MyContext, interaction: Comman
6870 } catch ( e ) {
6971 console . error ( e ) ;
7072 const errorMessage = "An error has occurred" ;
71- interaction
72- . reply ( {
73- content : errorMessage ,
74- ephemeral : true ,
75- } )
76- . catch ( console . error ) ;
73+ await interaction [ interaction . replied ? "editReply" : "reply" ] ?.( {
74+ content : errorMessage ,
75+ } ) . catch ( console . error ) ;
7776 }
7877}
7978async function selectMenuInteractionHandler ( context : MyContext , interaction : SelectMenuInteraction ) {
79+ await interaction . deferUpdate ( ) . catch ( console . error ) ;
8080 const CommandName = interaction . customId . split ( "/" ) [ 0 ] ;
8181 switch ( CommandName ) {
8282 case "mdnselect" : {
@@ -87,7 +87,7 @@ async function selectMenuInteractionHandler(context: MyContext, interaction: Sel
8787
8888 // Remove the menu and update the ephemeral message
8989 await interaction
90- . update ( { content : "Sent documentations for " + selectedValue , components : [ ] } )
90+ . editReply ( { content : "Sent documentations for " + selectedValue , components : [ ] } )
9191 . catch ( console . error ) ;
9292 // Send documentation
9393 await interaction . followUp ( { embeds : [ resultEmbed ] , components : [ deleteButtonRow ] } ) . catch ( console . error ) ;
@@ -105,14 +105,14 @@ async function selectMenuInteractionHandler(context: MyContext, interaction: Sel
105105
106106 // Remove the menu and update the ephemeral message
107107 await interaction
108- . update ( { content : "Sent documentations for " + selectedValue , components : [ ] } )
108+ . editReply ( { content : "Sent documentations for " + selectedValue , components : [ ] } )
109109 . catch ( console . error ) ;
110110 // Send documentation
111111 await interaction . followUp ( { embeds : [ resultEmbed ] , components : [ deleteButtonRow ] } ) . catch ( console . error ) ;
112112 break ;
113113 }
114114 default : {
115- interaction . reply ( { content : "Unknown menu" , ephemeral : true } ) . catch ( console . error ) ;
115+ interaction . editReply ( { content : "Unknown menu" } ) . catch ( console . error ) ;
116116 }
117117 }
118118}
0 commit comments