diff --git a/src/api/Routes/interactions.ts b/src/api/Routes/interactions.ts index 75621fe..61a0eeb 100644 --- a/src/api/Routes/interactions.ts +++ b/src/api/Routes/interactions.ts @@ -9,6 +9,20 @@ import type { RestArguments } from '../api'; export interface InteractionRoutes { interactions: (id: string) => (token: string) => { callback: { + post( + args: RestArguments< + ProxyRequestMethod.Post, + RESTPostAPIInteractionCallbackJSONBody, + Omit & { with_response: true } + >, + ): Promise; + post( + args: RestArguments< + ProxyRequestMethod.Post, + RESTPostAPIInteractionCallbackJSONBody, + Omit & { with_response: false } + >, + ): Promise; post( args: RestArguments< ProxyRequestMethod.Post, diff --git a/src/client/base.ts b/src/client/base.ts index c600ae6..a39279f 100644 --- a/src/client/base.ts +++ b/src/client/base.ts @@ -6,6 +6,7 @@ import type { Command, CommandContext, ContextMenuCommand, + EntryPointCommand, ExtraProps, MenuCommandContext, RegisteredMiddlewares, @@ -319,10 +320,12 @@ export class BaseClient { BaseClient.assertString(applicationId, 'applicationId is not a string'); const commands = this.commands!.values; - const filter = filterSplit(commands, command => !command.guildId); + const filter = filterSplit< + Omit | EntryPointCommand, + MakeRequired + >(commands, command => ('guildId' in command ? !command.guildId : true)); if (this.commands?.entryPoint) { - // @ts-expect-error filter.expect.push(this.commands.entryPoint); } @@ -336,7 +339,7 @@ export class BaseClient { const guilds = new Set(); for (const command of filter.never) { - for (const guild_id of command.guildId!) { + for (const guild_id of command.guildId) { guilds.add(guild_id); } } @@ -349,7 +352,7 @@ export class BaseClient { .commands.put({ body: filter.never .filter( - cmd => cmd.guildId?.includes(guildId) && (!('ignore' in cmd) || cmd.ignore !== IgnoreCommand.Slash), + cmd => cmd.guildId.includes(guildId) && (!('ignore' in cmd) || cmd.ignore !== IgnoreCommand.Slash), ) .map(x => x.toJSON()), }); diff --git a/src/commands/applications/entrycontext.ts b/src/commands/applications/entrycontext.ts index 4c2b39f..6469671 100644 --- a/src/commands/applications/entrycontext.ts +++ b/src/commands/applications/entrycontext.ts @@ -79,7 +79,7 @@ export class EntryPointContext ex channel(mode?: 'rest' | 'flow'): Promise; channel(mode?: 'cache'): ReturnCache; channel(mode: 'cache' | 'rest' | 'flow' = 'cache') { - if (this.interaction?.channel && mode === 'cache') + if (this.interaction.channel && mode === 'cache') return this.client.cache.adapter.isAsync ? Promise.resolve(this.interaction.channel) : this.interaction.channel; return this.client.channels.fetch(this.channelId, mode === 'rest'); } diff --git a/src/common/it/utils.ts b/src/common/it/utils.ts index e837046..11ca577 100644 --- a/src/common/it/utils.ts +++ b/src/common/it/utils.ts @@ -96,14 +96,17 @@ export function MergeOptions(defaults: any, ...options: any[]): T { * @param func The predicate function used to test elements of the array. * @returns An object containing two arrays: one with elements that passed the test and one with elements that did not. */ -export function filterSplit boolean>(arr: Element[], func: Predicate) { +export function filterSplit( + arr: (Element | Never)[], + func: (value: Element | Never) => boolean, +) { const expect: Element[] = []; - const never: Element[] = []; + const never: Never[] = []; for (const element of arr) { const test = func(element); - if (test) expect.push(element); - else never.push(element); + if (test) expect.push(element as Element); + else never.push(element as Never); } return { expect, never }; diff --git a/src/structures/Interaction.ts b/src/structures/Interaction.ts index d57f942..33a5d94 100644 --- a/src/structures/Interaction.ts +++ b/src/structures/Interaction.ts @@ -39,7 +39,6 @@ import { type APIEntryPointCommandInteraction, type InteractionCallbackData, type InteractionCallbackResourceActivity, - type RESTPostAPIInteractionCallbackResult, } from '../types'; import type { RawFile } from '../api'; @@ -509,12 +508,12 @@ export class EntryPointInteraction extends files = files ? await resolveFiles(files) : undefined; body = BaseInteraction.transformBody(rest, files, this.client); } - const response = (await this.client.proxy + const response = await this.client.proxy .interactions(this.id)(this.token) .callback.post({ body, query: { with_response: true }, - })) as RESTPostAPIInteractionCallbackResult; + }); const result: Partial = { interaction: toCamelCase(response.interaction),