1- import { Dirent , readdirSync } from 'node:fs' ;
2- import { stat } from 'node:fs/promises' ;
3- import { join } from 'node:path' ;
41import ky from 'ky' ;
5- import { AppCommand } from '../models/AppCommand.js' ;
6- import { InvalidAppCommandError , InvalidHookPath } from '../models/errors.js' ;
7- import { Awaitable } from '../typings.js' ;
8- import { Router } from '../router/Router.js' ;
92import { AppCommandType } from '../models/AppCommandShape.js' ;
3+ import { CommandUpdateError , InvalidAppCommandError } from '../models/errors.js' ;
4+ import { Router } from '../router/Router.js' ;
105
116export class AppCommandHandler < Args extends unknown [ ] > {
127 private readonly router : Router < Args > ;
138 private readonly clientId : string ;
149 private readonly token : string ;
1510
16- constructor ( router : Router < Args > , { clientId, token } : { clientId : string , token : string ; } ) {
11+ constructor ( router : Router < Args > , { clientId, token } : { clientId : string ; token : string } ) {
1712 this . router = router ;
1813 this . clientId = clientId ;
1914 this . token = token ;
@@ -22,19 +17,19 @@ export class AppCommandHandler<Args extends unknown[]> {
2217 public async overwriteCommands ( ) : Promise < void > {
2318 try {
2419 await ky . put ( `https://discord.com/api/v10/applications/${ this . clientId } /commands` , {
25- headers : { ' Authorization' : `Bot ${ this . token } ` } ,
20+ headers : { Authorization : `Bot ${ this . token } ` } ,
2621 json : this . router . commandData ,
2722 } ) ;
2823 } catch ( error ) {
29- throw new Error ( 'Failed to update Global Commands.' ) ;
24+ throw new CommandUpdateError ( 'Failed to overwrite commands:\n\t' + error ) ;
3025 }
3126 }
3227
3328 public async run ( commandName : string , commandType : AppCommandType , ...args : Args ) : Promise < void > {
3429 const commandFn = this . router . get ( commandName , commandType ) ;
3530
3631 if ( ! commandFn ) {
37- throw new InvalidAppCommandError ( `Command ${ commandName } does not exist.` , 'INVALID_COMMAND' ) ;
32+ throw new InvalidAppCommandError ( `Command ${ commandName } does not exist.` ) ;
3833 }
3934
4035 await commandFn ( ...args ) ;
0 commit comments