mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat: Backport Interaction#isRepliable (#7563)
This commit is contained in:
@@ -226,6 +226,16 @@ class Interaction extends Base {
|
||||
MessageComponentTypes[this.componentType] === MessageComponentTypes.SELECT_MENU
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this interaction can be replied to.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isRepliable() {
|
||||
return ![InteractionTypes.PING, InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE].includes(
|
||||
InteractionTypes[this.type],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Interaction;
|
||||
|
||||
16
typings/index.d.ts
vendored
16
typings/index.d.ts
vendored
@@ -321,6 +321,21 @@ 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<GuildCacheMessage<Cached>>;
|
||||
reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>;
|
||||
deleteReply(): Promise<void>;
|
||||
editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<GuildCacheMessage<Cached>>;
|
||||
deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
|
||||
deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
|
||||
fetchReply(): Promise<GuildCacheMessage<Cached>>;
|
||||
followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<GuildCacheMessage<Cached>>;
|
||||
}
|
||||
|
||||
export abstract class BaseCommandInteraction<Cached extends CacheType = CacheType> extends Interaction<Cached> {
|
||||
public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null;
|
||||
public options: Omit<
|
||||
@@ -1352,6 +1367,7 @@ export class Interaction<Cached extends CacheType = CacheType> extends Base {
|
||||
public isMessageContextMenu(): this is MessageContextMenuInteraction<Cached>;
|
||||
public isMessageComponent(): this is MessageComponentInteraction<Cached>;
|
||||
public isSelectMenu(): this is SelectMenuInteraction<Cached>;
|
||||
public isRepliable(): this is this & InteractionResponseFields<Cached>;
|
||||
}
|
||||
|
||||
export class InteractionCollector<T extends Interaction> extends Collector<Snowflake, T> {
|
||||
|
||||
@@ -93,6 +93,7 @@ import {
|
||||
MessageActionRowComponent,
|
||||
MessageSelectMenu,
|
||||
PartialDMChannel,
|
||||
InteractionResponseFields,
|
||||
} from '.';
|
||||
import type { ApplicationCommandOptionTypes } from './enums';
|
||||
import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd';
|
||||
@@ -1145,6 +1146,16 @@ client.on('interactionCreate', async interaction => {
|
||||
expectType<string | null>(interaction.options.getSubcommandGroup(booleanValue));
|
||||
expectType<string | null>(interaction.options.getSubcommandGroup(false));
|
||||
}
|
||||
|
||||
if (interaction.isRepliable()) {
|
||||
expectAssignable<InteractionResponseFields>(interaction);
|
||||
interaction.reply('test');
|
||||
}
|
||||
|
||||
if (interaction.isCommand() && interaction.isRepliable()) {
|
||||
expectAssignable<CommandInteraction>(interaction);
|
||||
expectAssignable<InteractionResponseFields>(interaction);
|
||||
}
|
||||
});
|
||||
|
||||
declare const shard: Shard;
|
||||
|
||||
Reference in New Issue
Block a user