@@ -2,7 +2,7 @@ import { Client, REST, Routes } from 'discord.js'
22import consola from 'consola'
33import type { Harmonix } from './types'
44import 'dotenv/config'
5- import { createError } from './harmonix'
5+ import { createError , ctx } from './harmonix'
66import { contextMenuToJSON , isHarmonixCommand , slashToJSON } from './utils'
77
88export const initCient = ( harmonixOptions : Harmonix [ 'options' ] ) => {
@@ -20,20 +20,27 @@ export const refreshApplicationCommands = async (harmonix: Harmonix) => {
2020 ]
2121 const rest = new REST ( ) . setToken ( process . env . HARMONIX_CLIENT_TOKEN ! )
2222
23- try {
24- consola . info ( 'Started refreshing application commands.' )
25- await rest . put (
26- Routes . applicationCommands (
27- harmonix . options . clientId || process . env . HARMONIX_CLIENT_ID || ''
28- ) ,
29- {
30- body : commands . map ( ( cmd ) =>
31- isHarmonixCommand ( cmd ) ? slashToJSON ( cmd ) : contextMenuToJSON ( cmd )
32- )
23+ harmonix . client ?. once ( 'ready' , async ( ) => {
24+ try {
25+ consola . info ( 'Started refreshing application commands.' )
26+ await rest . put (
27+ Routes . applicationCommands (
28+ harmonix . options . clientId || harmonix . client ?. user ?. id || ''
29+ ) ,
30+ {
31+ body : commands . map ( ( cmd ) =>
32+ isHarmonixCommand ( cmd ) ? slashToJSON ( cmd ) : contextMenuToJSON ( cmd )
33+ )
34+ }
35+ )
36+ consola . success ( 'Successfully reloaded application commands.\n' )
37+ const readyEvent = harmonix . events . get ( 'ready' )
38+
39+ if ( readyEvent ) {
40+ ctx . call ( harmonix , ( ) => readyEvent . callback ( harmonix . client as any ) )
3341 }
34- )
35- consola . success ( 'Successfully reloaded application commands.\n' )
36- } catch ( error : any ) {
37- createError ( error . message )
38- }
42+ } catch ( error : any ) {
43+ createError ( error . message )
44+ }
45+ } )
3946}
0 commit comments