Skip to content

Commit 7458310

Browse files
committed
fix: if no clientId is specify, client id of the bot will be automatically used
1 parent 621c622 commit 7458310

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/discord.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Client, REST, Routes } from 'discord.js'
22
import consola from 'consola'
33
import type { Harmonix } from './types'
44
import 'dotenv/config'
5-
import { createError } from './harmonix'
5+
import { createError, ctx } from './harmonix'
66
import { contextMenuToJSON, isHarmonixCommand, slashToJSON } from './utils'
77

88
export 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
}

src/register.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { Harmonix, HarmonixEvents, ParsedArgs } from './types'
77

88
export const registerEvents = (harmonix: Harmonix) => {
99
for (const [, event] of harmonix.events.filter((evt) => !evt.options.type)) {
10+
if (event.options.name === 'ready') continue
1011
if (event.options.once) {
1112
harmonix.client?.once(event.options.name!, (...args) => {
1213
ctx.call(harmonix, () => {

0 commit comments

Comments
 (0)