diff --git a/example/imagine-dm.ts b/example/imagine-dm.ts index 8f9aa37..5c0fdaa 100644 --- a/example/imagine-dm.ts +++ b/example/imagine-dm.ts @@ -14,16 +14,16 @@ async function main() { Ws: true, }); await client.Connect(); - const info = await client.Info(); - console.log(info); - return - // const msg = await client.Imagine( - // "A little white dog", - // (uri: string, progress: string) => { - // console.log("loading", uri, "progress", progress); - // } - // ); - // console.log({ msg }); + // const info = await client.Info(); + // console.log(info); + // return + const msg = await client.Imagine( + "A little white dog", + (uri: string, progress: string) => { + console.log("loading", uri, "progress", progress); + } + ); + console.log({ msg }); } main() .then(() => { diff --git a/src/command.ts b/src/command.ts index 29dd65e..4a298db 100644 --- a/src/command.ts +++ b/src/command.ts @@ -36,20 +36,19 @@ export class Command { if (this.cache[name] !== undefined) { return this.cache[name]; } - if (this.config.ServerId) { - const command = await this.getCommand(name); - this.cache[name] = command; - return command; - } + const command = await this.getCommand(name); + console.log("=========", { command }); + this.cache[name] = command; + return command; this.allCommand(); return this.cache[name]; } async allCommand() { - const searchParams = new URLSearchParams({ - type: "1", - include_applications: "true", - }); - const url = `${this.config.DiscordBaseUrl}/api/v9/guilds/${this.config.ServerId}/application-command-index`; + let serverId = this.config.ServerId; + if (!serverId) { + serverId = this.config.ChannelId; + } + const url = `${this.config.DiscordBaseUrl}/api/v9/guilds/${serverId}/application-command-index`; const response = await this.safeFetch(url, { headers: { authorization: this.config.SalaiToken }, }); @@ -66,7 +65,11 @@ export class Command { } async getCommand(name: CommandName) { - const url = `${this.config.DiscordBaseUrl}/api/v9/guilds/${this.config.ServerId}/application-command-index`; + let serverId = this.config.ServerId; + if (!serverId) { + serverId = this.config.ChannelId; + } + const url = `${this.config.DiscordBaseUrl}/api/v9/guilds/${serverId}/application-command-index`; const response = await this.safeFetch(url, { headers: { authorization: this.config.SalaiToken }, });