mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
feat: add typeguard to BaseInteraction#isRepliable (#8565)
* feat: add typeguard to BaseInteraction#isRepliable * fix: redefine RepliableInteraaction ...to exclude impossible interactions rather than specify possible ones Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * fix: remove InteractionResponseFields * fix: replace InteractionResponseFields with RepliableInteraction in index test Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
25
packages/discord.js/typings/index.d.ts
vendored
25
packages/discord.js/typings/index.d.ts
vendored
@@ -398,28 +398,6 @@ export type GuildCacheMessage<Cached extends CacheType> = CacheTypeReducer<
|
||||
Message | APIMessage
|
||||
>;
|
||||
|
||||
export interface InteractionResponseFields<Cached extends CacheType = CacheType> {
|
||||
deferred: boolean;
|
||||
ephemeral: boolean | null;
|
||||
replied: boolean;
|
||||
webhook: InteractionWebhook;
|
||||
reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<Message>;
|
||||
reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>;
|
||||
deleteReply(): Promise<void>;
|
||||
editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<Message>;
|
||||
deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<Message>;
|
||||
deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
|
||||
fetchReply(): Promise<Message>;
|
||||
followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<Message>;
|
||||
showModal(
|
||||
modal:
|
||||
| JSONEncodable<APIModalInteractionResponseCallbackData>
|
||||
| ModalComponentData
|
||||
| APIModalInteractionResponseCallbackData,
|
||||
): Promise<void>;
|
||||
awaitModalSubmit(options: AwaitModalSubmitOptions<ModalSubmitInteraction>): Promise<ModalSubmitInteraction<Cached>>;
|
||||
}
|
||||
|
||||
export type BooleanCache<T extends CacheType> = T extends 'cached' ? true : false;
|
||||
|
||||
export abstract class CommandInteraction<Cached extends CacheType = CacheType> extends BaseInteraction<Cached> {
|
||||
@@ -1504,6 +1482,7 @@ export type Interaction<Cached extends CacheType = CacheType> =
|
||||
| AutocompleteInteraction<Cached>
|
||||
| ModalSubmitInteraction<Cached>;
|
||||
|
||||
export type RepliableInteraction<Cached extends CacheType = CacheType> = Exclude<Interaction, AutocompleteInteraction>;
|
||||
export class BaseInteraction<Cached extends CacheType = CacheType> extends Base {
|
||||
// This a technique used to brand different cached types. Or else we'll get `never` errors on typeguard checks.
|
||||
private readonly _cacheType: Cached;
|
||||
@@ -1544,7 +1523,7 @@ export class BaseInteraction<Cached extends CacheType = CacheType> extends Base
|
||||
public isModalSubmit(): this is ModalSubmitInteraction<Cached>;
|
||||
public isUserContextMenuCommand(): this is UserContextMenuCommandInteraction<Cached>;
|
||||
public isSelectMenu(): this is SelectMenuInteraction<Cached>;
|
||||
public isRepliable(): this is this & InteractionResponseFields<Cached>;
|
||||
public isRepliable(): this is RepliableInteraction<Cached>;
|
||||
}
|
||||
|
||||
export class InteractionCollector<T extends CollectedInteraction> extends Collector<
|
||||
|
||||
@@ -100,7 +100,7 @@ import {
|
||||
ActionRowBuilder,
|
||||
ButtonComponent,
|
||||
SelectMenuComponent,
|
||||
InteractionResponseFields,
|
||||
RepliableInteraction,
|
||||
ThreadChannelType,
|
||||
Events,
|
||||
WebSocketShardEvents,
|
||||
@@ -1519,7 +1519,7 @@ client.on('interactionCreate', async interaction => {
|
||||
}
|
||||
|
||||
if (interaction.isRepliable()) {
|
||||
expectAssignable<InteractionResponseFields>(interaction);
|
||||
expectAssignable<RepliableInteraction>(interaction);
|
||||
interaction.reply('test');
|
||||
}
|
||||
|
||||
@@ -1529,7 +1529,7 @@ client.on('interactionCreate', async interaction => {
|
||||
interaction.isRepliable()
|
||||
) {
|
||||
expectAssignable<CommandInteraction>(interaction);
|
||||
expectAssignable<InteractionResponseFields>(interaction);
|
||||
expectAssignable<RepliableInteraction>(interaction);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user