@@ -10,12 +10,13 @@ import {
1010import * as fs from "fs" ;
1111import * as path from "path" ;
1212import { fileURLToPath , pathToFileURL } from "url" ;
13+ import { logger } from "./logger.js" ;
1314
1415export interface Command {
1516 data :
16- | SlashCommandBuilder
17- | SlashCommandSubcommandsOnlyBuilder
18- | Omit < SlashCommandBuilder , "addSubcommand" | "addSubcommandGroup" > ;
17+ | SlashCommandBuilder
18+ | SlashCommandSubcommandsOnlyBuilder
19+ | Omit < SlashCommandBuilder , "addSubcommand" | "addSubcommandGroup" > ;
1920 execute : ( interaction : ChatInputCommandInteraction ) => Promise < void > ;
2021}
2122
@@ -24,8 +25,8 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url));
2425export async function loadCommands (
2526 client : Client & { commands ?: Collection < string , Command > } ,
2627 clientId : string ,
27- guildId : string ,
28- token : string
28+ token : string ,
29+ guildId ? : string ,
2930) : Promise < void > {
3031 client . commands = new Collection < string , Command > ( ) ;
3132
@@ -48,11 +49,23 @@ export async function loadCommands(
4849
4950 const rest = new REST ( ) . setToken ( token ) ;
5051
51- await rest . put ( Routes . applicationGuildCommands ( clientId , guildId ) , {
52- body : [ ] ,
53- } ) ;
52+ if ( clientId && guildId ) {
53+ logger . info ( "here" )
54+ await rest . put ( Routes . applicationGuildCommands ( clientId , guildId ) , {
55+ body : [ ] ,
56+ } ) ;
5457
55- await rest . put ( Routes . applicationGuildCommands ( clientId , guildId ) , {
56- body : commandData ,
57- } ) ;
58+ await rest . put ( Routes . applicationGuildCommands ( clientId , guildId ) , {
59+ body : commandData ,
60+ } ) ;
61+ } else if ( clientId ) {
62+ logger . info ( "a" )
63+ await rest . put ( Routes . applicationCommands ( clientId ) , {
64+ body : [ ] ,
65+ } ) ;
66+
67+ await rest . put ( Routes . applicationCommands ( clientId ) , {
68+ body : commandData ,
69+ } ) ;
70+ }
5871}
0 commit comments