import { Collection } from 'discord.js' ; import { readdirSync } from 'fs' ; import type { Client , Message , PermissionString } from 'discord.js' ; type CommandCategory = 'Documentation' | 'Economy' | 'Fun' | 'Levelling' | 'Miscellaneous' | 'Music' | 'Moderation' | 'Utility' ; export interface HelpObj { aliases : string [ ] ; category : CommandCategory ; desc : string ; dm ? : true ; private ? : boolean ; togglable : boolean ; usage : string ; } interface ReknownCommand { help : HelpObj ; memberPerms : PermissionString [ ] ; permissions : PermissionString [ ] ; run : ( client : Client , message : Message , args : string [ ] ) => void ; } export default class CommandHandler extends Collection < string , ReknownCommand > { public constructor ( ) { super ( ) ; this . rawCategories = readdirSync ( './dist/commands' ) ; this . rawCategories . forEach ( c => readdirSync ( `./dist/commands/${ c }` ) . forEach ( cmd => { this . list . push ( cmd . slice ( 0 , - 3 ) ) ; const command = require ( `../commands/${ c }/${ cmd }` ) ; this . set ( cmd . slice ( 0 , - 3 ) , command ) ; command . help . aliases . forEach ( alias => this . aliases [ alias ] = cmd . slice ( 0 , - 3 ) ) ; this . aliases [ cmd . slice ( 0 , - 3 ) ] = cmd . slice ( 0 , - 3 ) ; if ( ! this . categories . includes ( command . help . category ) ) this . categories . push ( command . help . category ) ; } ) ) ; } public aliases : { [ alias ] : string ; } = { } ; public categories : CommandCategory [ ] = [ ] ; public list : string [ ] = [ ] ; public rawCategories : string [ ] = [ ] ; }