Skip to content

Commit 5e8162a

Browse files
authoredApr 9, 2022
feat: Backport Interaction#isRepliable (#7563)
1 parent 9f09702 commit 5e8162a

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed
 

‎src/structures/Interaction.js

+10
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,16 @@ class Interaction extends Base {
226226
MessageComponentTypes[this.componentType] === MessageComponentTypes.SELECT_MENU
227227
);
228228
}
229+
230+
/**
231+
* Indicates whether this interaction can be replied to.
232+
* @returns {boolean}
233+
*/
234+
isRepliable() {
235+
return ![InteractionTypes.PING, InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE].includes(
236+
InteractionTypes[this.type],
237+
);
238+
}
229239
}
230240

231241
module.exports = Interaction;

‎typings/index.d.ts

+16
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,21 @@ export type GuildCacheMessage<Cached extends CacheType> = CacheTypeReducer<
321321
Message | APIMessage
322322
>;
323323

324+
export interface InteractionResponseFields<Cached extends CacheType = CacheType> {
325+
deferred: boolean;
326+
ephemeral: boolean | null;
327+
replied: boolean;
328+
webhook: InteractionWebhook;
329+
reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
330+
reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>;
331+
deleteReply(): Promise<void>;
332+
editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<GuildCacheMessage<Cached>>;
333+
deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
334+
deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
335+
fetchReply(): Promise<GuildCacheMessage<Cached>>;
336+
followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<GuildCacheMessage<Cached>>;
337+
}
338+
324339
export abstract class BaseCommandInteraction<Cached extends CacheType = CacheType> extends Interaction<Cached> {
325340
public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null;
326341
public options: Omit<
@@ -1352,6 +1367,7 @@ export class Interaction<Cached extends CacheType = CacheType> extends Base {
13521367
public isMessageContextMenu(): this is MessageContextMenuInteraction<Cached>;
13531368
public isMessageComponent(): this is MessageComponentInteraction<Cached>;
13541369
public isSelectMenu(): this is SelectMenuInteraction<Cached>;
1370+
public isRepliable(): this is this & InteractionResponseFields<Cached>;
13551371
}
13561372

13571373
export class InteractionCollector<T extends Interaction> extends Collector<Snowflake, T> {

‎typings/index.test-d.ts

+11
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import {
9393
MessageActionRowComponent,
9494
MessageSelectMenu,
9595
PartialDMChannel,
96+
InteractionResponseFields,
9697
} from '.';
9798
import type { ApplicationCommandOptionTypes } from './enums';
9899
import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd';
@@ -1145,6 +1146,16 @@ client.on('interactionCreate', async interaction => {
11451146
expectType<string | null>(interaction.options.getSubcommandGroup(booleanValue));
11461147
expectType<string | null>(interaction.options.getSubcommandGroup(false));
11471148
}
1149+
1150+
if (interaction.isRepliable()) {
1151+
expectAssignable<InteractionResponseFields>(interaction);
1152+
interaction.reply('test');
1153+
}
1154+
1155+
if (interaction.isCommand() && interaction.isRepliable()) {
1156+
expectAssignable<CommandInteraction>(interaction);
1157+
expectAssignable<InteractionResponseFields>(interaction);
1158+
}
11481159
});
11491160

11501161
declare const shard: Shard;

0 commit comments

Comments
 (0)