@@ -19,23 +19,36 @@ import type {
1919} from "discord.js" ;
2020
2121export interface ModuleLoaderOptions {
22- disallowedChannelMessage : string ;
23- commandCooldownMessage : string ;
22+ unknownCommandMessage ?: string ;
23+ disabledCommandMessage ?: string ;
24+ disallowedChannelMessage ?: string ;
25+ commandCooldownMessage ?: string ;
2426}
2527
2628export default class DiscordModuleLoader {
29+ unknownCommandMessage =
30+ "Couldn't find executed command. Please try again later, or report the issue." ;
31+ disabledCommandMessage =
32+ "This command is currently disabled. Please try again later." ;
2733 disallowedChannelMessage =
2834 "You're not allowed to execute this command in this channel!" ;
2935 commandCooldownMessage =
3036 "Please wait % seconds before using this command again." ;
3137
32- commands : Collection < string , DiscordCommand > = new Collection ( ) ;
33- modules : Collection < string , DiscordModule > = new Collection ( ) ;
34- guilds : Collection < string , DiscordGuild > = new Collection ( ) ;
35- cooldowns : Collection < string , Collection < string , number > > = new Collection ( ) ;
38+ events = new Collection < string , DiscordEvent < any > > ( ) ;
39+ commands = new Collection < string , DiscordCommand > ( ) ;
40+ modules = new Collection < string , DiscordModule > ( ) ;
41+ guilds = new Collection < string , DiscordGuild > ( ) ;
42+ cooldowns = new Collection < string , Collection < string , number > > ( ) ;
3643 log = debug ( "Discord-Module-Loader" ) ;
3744
3845 constructor ( public client : Client , options ?: ModuleLoaderOptions ) {
46+ if ( options ?. unknownCommandMessage )
47+ this . unknownCommandMessage = options . unknownCommandMessage ;
48+
49+ if ( options ?. disabledCommandMessage )
50+ this . disabledCommandMessage = options . disabledCommandMessage ;
51+
3952 if ( options ?. disallowedChannelMessage )
4053 this . disallowedChannelMessage = options . disallowedChannelMessage ;
4154
@@ -169,7 +182,11 @@ export default class DiscordModuleLoader {
169182 if ( ! ( event instanceof DiscordEvent ) )
170183 throw new Error ( `Event ${ file } is not an Event` ) ;
171184
172- this . client . on ( event . event , event . listener ) ;
185+ this . client . on ( event . event , ( ...args ) => {
186+ if ( ! event . disabled ) event . listener ( ...args ) ;
187+ } ) ;
188+
189+ this . events . set ( event . event , event ) ;
173190 returnEvents . push ( [ event . event , event ] ) ;
174191 log ( "Loaded event %s" , event . event ) ;
175192 }
@@ -310,7 +327,17 @@ export default class DiscordModuleLoader {
310327 private async handleInteraction ( interaction : Interaction < CacheType > ) {
311328 if ( interaction . isCommand ( ) || interaction . isContextMenu ( ) ) {
312329 const command = this . commands . get ( interaction . commandName . toLowerCase ( ) ) ;
313- if ( ! command ) return ;
330+ if ( ! command )
331+ return await interaction . reply ( {
332+ content : this . unknownCommandMessage ,
333+ ephemeral : true
334+ } ) ;
335+
336+ if ( command . disabled )
337+ return await interaction . reply ( {
338+ content : this . disabledCommandMessage ,
339+ ephemeral : true
340+ } ) ;
314341
315342 let allowed = true ;
316343 if (
0 commit comments