refactor(interactions): remove redundant interaction typeguards (#8027)

This commit is contained in:
Suneet Tipirneni
2022-06-09 14:52:44 -04:00
committed by GitHub
parent d7b8357dcb
commit f57d6768ad
4 changed files with 135 additions and 126 deletions

View File

@@ -186,20 +186,12 @@ class Interaction extends Base {
return Boolean(this.guildId && !this.guild && this.member);
}
/**
* Indicates whether this interaction is a {@link CommandInteraction}.
* @returns {boolean}
*/
isCommand() {
return this.type === InteractionType.ApplicationCommand;
}
/**
* Indicates whether this interaction is a {@link ChatInputCommandInteraction}.
* @returns {boolean}
*/
isChatInputCommand() {
return this.isCommand() && this.commandType === ApplicationCommandType.ChatInput;
return this.type === InteractionType.ApplicationCommand && this.commandType === ApplicationCommandType.ChatInput;
}
/**
@@ -207,7 +199,10 @@ class Interaction extends Base {
* @returns {boolean}
*/
isContextMenuCommand() {
return this.isCommand() && [ApplicationCommandType.User, ApplicationCommandType.Message].includes(this.commandType);
return (
this.type === InteractionType.ApplicationCommand &&
[ApplicationCommandType.User, ApplicationCommandType.Message].includes(this.commandType)
);
}
/**
@@ -226,36 +221,12 @@ class Interaction extends Base {
return this.isContextMenuCommand() && this.commandType === ApplicationCommandType.Message;
}
/**
* Indicates whether this interaction is a {@link ModalSubmitInteraction}
* @returns {boolean}
*/
isModalSubmit() {
return this.type === InteractionType.ModalSubmit;
}
/**
* Indicates whether this interaction is an {@link AutocompleteInteraction}
* @returns {boolean}
*/
isAutocomplete() {
return this.type === InteractionType.ApplicationCommandAutocomplete;
}
/**
* Indicates whether this interaction is a {@link MessageComponentInteraction}.
* @returns {boolean}
*/
isMessageComponent() {
return this.type === InteractionType.MessageComponent;
}
/**
* Indicates whether this interaction is a {@link ButtonInteraction}.
* @returns {boolean}
*/
isButton() {
return this.isMessageComponent() && this.componentType === ComponentType.Button;
return this.type === InteractionType.MessageComponent && this.componentType === ComponentType.Button;
}
/**
@@ -263,7 +234,7 @@ class Interaction extends Base {
* @returns {boolean}
*/
isSelectMenu() {
return this.isMessageComponent() && this.componentType === ComponentType.SelectMenu;
return this.type === InteractionType.MessageComponent && this.componentType === ComponentType.SelectMenu;
}
/**

View File

@@ -511,14 +511,6 @@ class ThreadChannel extends Channel {
return this.archived && this.sendable && (!this.locked || this.manageable);
}
/**
* Whether this thread is a private thread
* @returns {boolean}
*/
isPrivate() {
return this.type === ChannelType.GuildPrivateThread;
}
/**
* Deletes this thread.
* @param {string} [reason] Reason for deleting this thread

View File

@@ -412,6 +412,7 @@ export interface InteractionResponseFields<Cached extends CacheType = CacheType>
export type BooleanCache<T extends CacheType> = T extends 'cached' ? true : false;
export abstract class CommandInteraction<Cached extends CacheType = CacheType> extends Interaction<Cached> {
public type: InteractionType.ApplicationCommand;
public get command(): ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null;
public options: Omit<
CommandInteractionOptionResolver<Cached>,
@@ -564,6 +565,7 @@ export class BitField<S extends string, N extends number | bigint = number> {
export class ButtonInteraction<Cached extends CacheType = CacheType> extends MessageComponentInteraction<Cached> {
private constructor(client: Client, data: RawMessageButtonInteractionData);
public componentType: ComponentType.Button;
public get component(): CacheTypeReducer<
Cached,
ButtonComponent,
@@ -571,7 +573,6 @@ export class ButtonInteraction<Cached extends CacheType = CacheType> extends Mes
ButtonComponent | APIButtonComponent,
ButtonComponent | APIButtonComponent
>;
public componentType: ComponentType.Button;
public inGuild(): this is ButtonInteraction<'raw' | 'cached'>;
public inCachedGuild(): this is ButtonInteraction<'cached'>;
public inRawGuild(): this is ButtonInteraction<'raw'>;
@@ -750,7 +751,7 @@ export abstract class Channel extends Base {
public get url(): string;
public delete(): Promise<this>;
public fetch(force?: boolean): Promise<this>;
public isThread(): this is ThreadChannel;
public isThread(): this is AnyThreadChannel;
public isTextBased(): this is TextBasedChannel;
public isDMBased(): this is PartialGroupDMChannel | DMChannel | PartialDMChannel;
public isVoiceBased(): this is VoiceBasedChannel;
@@ -918,6 +919,7 @@ export abstract class Collector<K, V, F extends unknown[] = []> extends EventEmi
}
export class ChatInputCommandInteraction<Cached extends CacheType = CacheType> extends CommandInteraction<Cached> {
public commandType: ApplicationCommandType.ChatInput;
public options: Omit<CommandInteractionOptionResolver<Cached>, 'getMessage' | 'getFocused'>;
public inGuild(): this is ChatInputCommandInteraction<'raw' | 'cached'>;
public inCachedGuild(): this is ChatInputCommandInteraction<'cached'>;
@@ -926,6 +928,7 @@ export class ChatInputCommandInteraction<Cached extends CacheType = CacheType> e
}
export class AutocompleteInteraction<Cached extends CacheType = CacheType> extends Interaction<Cached> {
public type: InteractionType.ApplicationCommandAutocomplete;
public get command(): ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null;
public channelId: Snowflake;
public commandId: Snowflake;
@@ -1002,6 +1005,7 @@ export class CommandInteractionOptionResolver<Cached extends CacheType = CacheTy
}
export class ContextMenuCommandInteraction<Cached extends CacheType = CacheType> extends CommandInteraction<Cached> {
public commandType: ApplicationCommandType.Message | ApplicationCommandType.User;
public options: Omit<
CommandInteractionOptionResolver<Cached>,
| 'getFocused'
@@ -1465,6 +1469,15 @@ export type CacheTypeReducer<
? PresentType
: Fallback;
export type AnyInteraction<Cached extends CacheType = CacheType> =
| ChatInputCommandInteraction<Cached>
| MessageContextMenuCommandInteraction<Cached>
| UserContextMenuCommandInteraction<Cached>
| SelectMenuInteraction<Cached>
| ButtonInteraction<Cached>
| AutocompleteInteraction<Cached>
| ModalSubmitInteraction<Cached>;
export class Interaction<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;
@@ -1495,16 +1508,13 @@ export class Interaction<Cached extends CacheType = CacheType> extends Base {
public inCachedGuild(): this is Interaction<'cached'>;
public inRawGuild(): this is Interaction<'raw'>;
public isButton(): this is ButtonInteraction<Cached>;
public isCommand(): this is CommandInteraction<Cached>;
public isChatInputCommand(): this is ChatInputCommandInteraction<Cached>;
public isContextMenuCommand(): this is ContextMenuCommandInteraction<Cached>;
public isMessageContextMenuCommand(): this is MessageContextMenuCommandInteraction<Cached>;
public isAutocomplete(): this is AutocompleteInteraction<Cached>;
public isUserContextMenuCommand(): this is UserContextMenuCommandInteraction<Cached>;
public isMessageComponent(): this is MessageComponentInteraction<Cached>;
public isSelectMenu(): this is SelectMenuInteraction<Cached>;
public isRepliable(): this is this & InteractionResponseFields<Cached>;
public isModalSubmit(): this is ModalSubmitInteraction<Cached>;
}
export class InteractionCollector<T extends Interaction> extends Collector<Snowflake, T, [Collection<Snowflake, T>]> {
@@ -1667,7 +1677,7 @@ export class Message<Cached extends boolean = boolean> extends Base {
public reactions: ReactionManager;
public stickers: Collection<Snowflake, Sticker>;
public system: boolean;
public get thread(): ThreadChannel | null;
public get thread(): AnyThreadChannel | null;
public tts: boolean;
public type: MessageType;
public get url(): string;
@@ -1694,7 +1704,7 @@ export class Message<Cached extends boolean = boolean> extends Base {
public removeAttachments(): Promise<Message>;
public reply(options: string | MessagePayload | ReplyMessageOptions): Promise<Message>;
public resolveComponent(customId: string): MessageActionRowComponent | null;
public startThread(options: StartThreadOptions): Promise<ThreadChannel>;
public startThread(options: StartThreadOptions): Promise<AnyThreadChannel>;
public suppressEmbeds(suppress?: boolean): Promise<Message>;
public toJSON(): unknown;
public toString(): string;
@@ -1748,6 +1758,7 @@ export class MessageCollector extends Collector<Snowflake, Message, [Collection<
export class MessageComponentInteraction<Cached extends CacheType = CacheType> extends Interaction<Cached> {
protected constructor(client: Client, data: RawMessageComponentInteractionData);
public type: InteractionType.MessageComponent;
public get component(): CacheTypeReducer<
Cached,
MessageActionRowComponent,
@@ -1755,7 +1766,7 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
MessageActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent<APIMessageActionRowComponent>>,
MessageActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent<APIMessageActionRowComponent>>
>;
public componentType: Exclude<ComponentType, ComponentType.ActionRow>;
public componentType: Exclude<ComponentType, ComponentType.ActionRow | ComponentType.TextInput>;
public customId: string;
public channelId: Snowflake;
public deferred: boolean;
@@ -1800,6 +1811,7 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
export class MessageContextMenuCommandInteraction<
Cached extends CacheType = CacheType,
> extends ContextMenuCommandInteraction<Cached> {
public commandType: ApplicationCommandType.Message;
public get targetMessage(): NonNullable<CommandInteractionOption<Cached>['message']>;
public inGuild(): this is MessageContextMenuCommandInteraction<'raw' | 'cached'>;
public inCachedGuild(): this is MessageContextMenuCommandInteraction<'cached'>;
@@ -1934,6 +1946,7 @@ export interface ModalMessageModalSubmitInteraction<Cached extends CacheType = C
export class ModalSubmitInteraction<Cached extends CacheType = CacheType> extends Interaction<Cached> {
private constructor(client: Client, data: APIModalSubmitInteraction);
public type: InteractionType.ModalSubmit;
public readonly customId: string;
public readonly components: ActionRowModalData[];
public readonly fields: ModalSubmitFields;
@@ -2439,6 +2452,18 @@ export class TextChannel extends BaseGuildTextChannel {
public setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise<TextChannel>;
}
export type AnyThreadChannel = PublicThreadChannel | PrivateThreadChannel;
export interface PublicThreadChannel extends ThreadChannel {
type: ChannelType.GuildPublicThread | ChannelType.GuildNewsThread;
}
export interface PrivateThreadChannel extends ThreadChannel {
get createdTimestamp(): number;
get createdAt(): Date;
type: ChannelType.GuildPrivateThread;
}
export class ThreadChannel extends TextBasedChannelMixin(Channel, ['fetchWebhooks', 'createWebhook']) {
private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client, fromInteraction?: boolean);
public archived: boolean | null;
@@ -2469,15 +2494,10 @@ export class ThreadChannel extends TextBasedChannelMixin(Channel, ['fetchWebhook
public rateLimitPerUser: number | null;
public type: ThreadChannelType;
public get unarchivable(): boolean;
public isPrivate(): this is this & {
get createdTimestamp(): number;
get createdAt(): Date;
type: ChannelType.GuildPrivateThread;
};
public delete(reason?: string): Promise<this>;
public edit(data: ThreadEditData, reason?: string): Promise<ThreadChannel>;
public join(): Promise<ThreadChannel>;
public leave(): Promise<ThreadChannel>;
public edit(data: ThreadEditData, reason?: string): Promise<AnyThreadChannel>;
public join(): Promise<AnyThreadChannel>;
public leave(): Promise<AnyThreadChannel>;
public permissionsFor(memberOrRole: GuildMember | Role, checkAdmin?: boolean): Readonly<PermissionsBitField>;
public permissionsFor(
memberOrRole: GuildMemberResolvable | RoleResolvable,
@@ -2485,15 +2505,15 @@ export class ThreadChannel extends TextBasedChannelMixin(Channel, ['fetchWebhook
): Readonly<PermissionsBitField> | null;
public fetchOwner(options?: BaseFetchOptions): Promise<ThreadMember | null>;
public fetchStarterMessage(options?: BaseFetchOptions): Promise<Message>;
public setArchived(archived?: boolean, reason?: string): Promise<ThreadChannel>;
public setArchived(archived?: boolean, reason?: string): Promise<AnyThreadChannel>;
public setAutoArchiveDuration(
autoArchiveDuration: ThreadAutoArchiveDuration,
reason?: string,
): Promise<ThreadChannel>;
public setInvitable(invitable?: boolean, reason?: string): Promise<ThreadChannel>;
public setLocked(locked?: boolean, reason?: string): Promise<ThreadChannel>;
public setName(name: string, reason?: string): Promise<ThreadChannel>;
public setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise<ThreadChannel>;
): Promise<AnyThreadChannel>;
public setInvitable(invitable?: boolean, reason?: string): Promise<AnyThreadChannel>;
public setLocked(locked?: boolean, reason?: string): Promise<AnyThreadChannel>;
public setName(name: string, reason?: string): Promise<AnyThreadChannel>;
public setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise<AnyThreadChannel>;
public toString(): ChannelMention;
}
@@ -2505,7 +2525,7 @@ export class ThreadMember extends Base {
public get joinedAt(): Date | null;
public joinedTimestamp: number | null;
public get manageable(): boolean;
public thread: ThreadChannel;
public thread: AnyThreadChannel;
public get user(): User | null;
public get partial(): false;
public remove(reason?: string): Promise<ThreadMember>;
@@ -2566,6 +2586,7 @@ export class User extends PartialTextBasedChannel(Base) {
export class UserContextMenuCommandInteraction<
Cached extends CacheType = CacheType,
> extends ContextMenuCommandInteraction<Cached> {
public commandType: ApplicationCommandType.User;
public get targetUser(): User;
public get targetMember(): CacheTypeReducer<Cached, GuildMember, APIInteractionGuildMember>;
public inGuild(): this is UserContextMenuCommandInteraction<'raw' | 'cached'>;
@@ -3371,8 +3392,8 @@ export class StageInstanceManager extends CachedManager<Snowflake, StageInstance
export class ThreadManager<AllowedThreadType> extends CachedManager<Snowflake, ThreadChannel, ThreadChannelResolvable> {
private constructor(channel: TextChannel | NewsChannel, iterable?: Iterable<RawThreadChannelData>);
public channel: TextChannel | NewsChannel;
public create(options: ThreadCreateOptions<AllowedThreadType>): Promise<ThreadChannel>;
public fetch(options: ThreadChannelResolvable, cacheOptions?: BaseFetchOptions): Promise<ThreadChannel | null>;
public create(options: ThreadCreateOptions<AllowedThreadType>): Promise<AnyThreadChannel>;
public fetch(options: ThreadChannelResolvable, cacheOptions?: BaseFetchOptions): Promise<AnyThreadChannel | null>;
public fetch(options?: FetchThreadsOptions, cacheOptions?: { cache?: boolean }): Promise<FetchedThreads>;
public fetchArchived(options?: FetchArchivedThreadOptions, cache?: boolean): Promise<FetchedThreads>;
public fetchActive(cache?: boolean): Promise<FetchedThreads>;
@@ -3380,7 +3401,7 @@ export class ThreadManager<AllowedThreadType> extends CachedManager<Snowflake, T
export class ThreadMemberManager extends CachedManager<Snowflake, ThreadMember, ThreadMemberResolvable> {
private constructor(thread: ThreadChannel, iterable?: Iterable<RawThreadMemberData>);
public thread: ThreadChannel;
public thread: AnyThreadChannel;
public get me(): ThreadMember | null;
public add(member: UserResolvable | '@me', reason?: string): Promise<Snowflake>;
public fetch(options?: ThreadMemberFetchOptions): Promise<ThreadMember>;
@@ -3886,21 +3907,21 @@ export interface ClientEvents {
roleCreate: [role: Role];
roleDelete: [role: Role];
roleUpdate: [oldRole: Role, newRole: Role];
threadCreate: [thread: ThreadChannel, newlyCreated: boolean];
threadDelete: [thread: ThreadChannel];
threadListSync: [threads: Collection<Snowflake, ThreadChannel>, guild: Guild];
threadCreate: [thread: AnyThreadChannel, newlyCreated: boolean];
threadDelete: [thread: AnyThreadChannel];
threadListSync: [threads: Collection<Snowflake, AnyThreadChannel>, guild: Guild];
threadMemberUpdate: [oldMember: ThreadMember, newMember: ThreadMember];
threadMembersUpdate: [
addedMembers: Collection<Snowflake, ThreadMember>,
removedMembers: Collection<Snowflake, ThreadMember | PartialThreadMember>,
thread: ThreadChannel,
thread: AnyThreadChannel,
];
threadUpdate: [oldThread: ThreadChannel, newThread: ThreadChannel];
threadUpdate: [oldThread: AnyThreadChannel, newThread: AnyThreadChannel];
typingStart: [typing: Typing];
userUpdate: [oldUser: User | PartialUser, newUser: User];
voiceStateUpdate: [oldState: VoiceState, newState: VoiceState];
webhookUpdate: [channel: TextChannel | NewsChannel | VoiceChannel];
interactionCreate: [interaction: Interaction];
interactionCreate: [interaction: AnyInteraction];
shardDisconnect: [closeEvent: CloseEvent, shardId: number];
shardError: [error: Error, shardId: number];
shardReady: [shardId: number, unavailableGuilds: Set<Snowflake> | undefined];
@@ -4222,7 +4243,7 @@ export interface FetchChannelOptions extends BaseFetchOptions {
}
export interface FetchedThreads {
threads: Collection<Snowflake, ThreadChannel>;
threads: Collection<Snowflake, AnyThreadChannel>;
hasMore?: boolean;
}
@@ -4398,7 +4419,7 @@ export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLo
Message: TActionType extends AuditLogEvent.MessageBulkDelete ? Guild | { id: Snowflake } : User;
Integration: Integration;
Channel: NonThreadGuildBasedChannel | { id: Snowflake; [x: string]: unknown };
Thread: ThreadChannel | { id: Snowflake; [x: string]: unknown };
Thread: AnyThreadChannel | { id: Snowflake; [x: string]: unknown };
StageInstance: StageInstance;
Sticker: Sticker;
GuildScheduledEvent: GuildScheduledEvent;
@@ -5115,7 +5136,7 @@ export interface SweeperDefinitions {
stageInstances: [Snowflake, StageInstance];
stickers: [Snowflake, Sticker];
threadMembers: [Snowflake, ThreadMember];
threads: [Snowflake, ThreadChannel, true];
threads: [Snowflake, AnyThreadChannel, true];
users: [Snowflake, User];
voiceStates: [Snowflake, VoiceState];
}
@@ -5139,7 +5160,7 @@ export type AnyChannel =
| NewsChannel
| StageChannel
| TextChannel
| ThreadChannel
| AnyThreadChannel
| VoiceChannel;
export type TextBasedChannel = Extract<AnyChannel, { messages: MessageManager }>;
@@ -5152,7 +5173,7 @@ export type GuildBasedChannel = Extract<AnyChannel, { guild: Guild }>;
export type NonCategoryGuildBasedChannel = Exclude<GuildBasedChannel, CategoryChannel>;
export type NonThreadGuildBasedChannel = Exclude<GuildBasedChannel, ThreadChannel>;
export type NonThreadGuildBasedChannel = Exclude<GuildBasedChannel, AnyThreadChannel>;
export type GuildTextBasedChannel = Extract<GuildBasedChannel, TextBasedChannel>;
@@ -5162,7 +5183,7 @@ export type TextBasedChannelResolvable = Snowflake | TextBasedChannel;
export type ThreadAutoArchiveDuration = 60 | 1440 | 4320 | 10080;
export type ThreadChannelResolvable = ThreadChannel | Snowflake;
export type ThreadChannelResolvable = AnyThreadChannel | Snowflake;
export type ThreadChannelType =
| ChannelType.GuildNewsThread

View File

@@ -21,6 +21,7 @@ import {
TextInputStyle,
APITextInputComponent,
APIEmbed,
ApplicationCommandType,
} from 'discord-api-types/v10';
import {
ApplicationCommand,
@@ -94,7 +95,6 @@ import {
GuildAuditLogsEntry,
GuildAuditLogs,
StageInstance,
PartialDMChannel,
ActionRowBuilder,
ButtonComponent,
SelectMenuComponent,
@@ -123,6 +123,9 @@ import {
UserMention,
PartialGroupDMChannel,
Attachment,
MessageContextMenuCommandInteraction,
UserContextMenuCommandInteraction,
AnyThreadChannel,
} from '.';
import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd';
import { UnsafeButtonBuilder, UnsafeEmbedBuilder, UnsafeSelectMenuBuilder } from '@discordjs/builders';
@@ -802,10 +805,20 @@ client.on('messageCreate', async message => {
channel.send({ components: [row, buttonsRow, selectsRow], embeds: [embed, buildersEmbed, embedData] });
});
client.on('threadCreate', thread => {
if (thread.type === ChannelType.GuildPrivateThread) {
expectType<number>(thread.createdTimestamp);
expectType<Date>(thread.createdAt);
} else {
expectType<number | null>(thread.createdTimestamp);
expectType<Date | null>(thread.createdAt);
}
});
client.on('threadMembersUpdate', (addedMembers, removedMembers, thread) => {
expectType<Collection<Snowflake, ThreadMember>>(addedMembers);
expectType<Collection<Snowflake, ThreadMember | PartialThreadMember>>(removedMembers);
expectType<ThreadChannel>(thread);
expectType<AnyThreadChannel>(thread);
const left = removedMembers.first();
if (!left) return;
@@ -823,7 +836,11 @@ client.on('interactionCreate', async interaction => {
expectType<Snowflake | null>(interaction.channelId);
expectType<GuildMember | APIInteractionGuildMember | null>(interaction.member);
if (!interaction.isCommand()) return;
if (interaction.type === InteractionType.MessageComponent) {
expectType<Snowflake>(interaction.channelId);
}
if (interaction.type !== InteractionType.ApplicationCommand) return;
void new ActionRowBuilder<MessageActionRowComponentBuilder>();
@@ -862,10 +879,6 @@ client.on('interactionCreate', async interaction => {
},
],
});
if (interaction.isMessageComponent()) {
expectType<Snowflake>(interaction.channelId);
}
});
client.login('absolutely-valid-token');
@@ -1153,6 +1166,31 @@ client.on('interactionCreate', interaction => {
});
client.on('interactionCreate', async interaction => {
if (interaction.type === InteractionType.MessageComponent) {
expectType<SelectMenuInteraction | ButtonInteraction>(interaction);
expectType<MessageActionRowComponent | APIButtonComponent | APISelectMenuComponent>(interaction.component);
expectType<Message>(interaction.message);
if (interaction.inCachedGuild()) {
expectAssignable<MessageComponentInteraction>(interaction);
expectType<MessageActionRowComponent>(interaction.component);
expectType<Message<true>>(interaction.message);
expectType<Guild>(interaction.guild);
expectAssignable<Promise<Message>>(interaction.reply({ fetchReply: true }));
} else if (interaction.inRawGuild()) {
expectAssignable<MessageComponentInteraction>(interaction);
expectType<APIButtonComponent | APISelectMenuComponent>(interaction.component);
expectType<Message<false>>(interaction.message);
expectType<null>(interaction.guild);
expectType<Promise<Message<false>>>(interaction.reply({ fetchReply: true }));
} else if (interaction.inGuild()) {
expectAssignable<MessageComponentInteraction>(interaction);
expectType<MessageActionRowComponent | APIButtonComponent | APISelectMenuComponent>(interaction.component);
expectType<Message>(interaction.message);
expectType<Guild | null>(interaction.guild);
expectType<Promise<Message>>(interaction.reply({ fetchReply: true }));
}
}
if (interaction.inCachedGuild()) {
expectAssignable<GuildMember>(interaction.member);
expectNotType<ChatInputCommandInteraction<'cached'>>(interaction);
@@ -1170,8 +1208,12 @@ client.on('interactionCreate', async interaction => {
expectType<string | null>(interaction.guildId);
}
if (interaction.isContextMenuCommand()) {
expectType<ContextMenuCommandInteraction>(interaction);
if (
interaction.type === InteractionType.ApplicationCommand &&
(interaction.commandType === ApplicationCommandType.User ||
interaction.commandType === ApplicationCommandType.Message)
) {
expectType<MessageContextMenuCommandInteraction | UserContextMenuCommandInteraction>(interaction);
if (interaction.inCachedGuild()) {
expectAssignable<ContextMenuCommandInteraction>(interaction);
expectAssignable<Guild>(interaction.guild);
@@ -1185,7 +1227,10 @@ client.on('interactionCreate', async interaction => {
}
}
if (interaction.isMessageContextMenuCommand()) {
if (
interaction.type === InteractionType.ApplicationCommand &&
interaction.commandType === ApplicationCommandType.Message
) {
expectType<Message>(interaction.targetMessage);
if (interaction.inCachedGuild()) {
expectType<Message<true>>(interaction.targetMessage);
@@ -1196,7 +1241,7 @@ client.on('interactionCreate', async interaction => {
}
}
if (interaction.isButton()) {
if (interaction.type === InteractionType.MessageComponent && interaction.componentType === ComponentType.Button) {
expectType<ButtonInteraction>(interaction);
expectType<ButtonComponent | APIButtonComponent>(interaction.component);
expectType<Message>(interaction.message);
@@ -1221,32 +1266,7 @@ client.on('interactionCreate', async interaction => {
}
}
if (interaction.isMessageComponent()) {
expectType<MessageComponentInteraction>(interaction);
expectType<MessageActionRowComponent | APIButtonComponent | APISelectMenuComponent>(interaction.component);
expectType<Message>(interaction.message);
if (interaction.inCachedGuild()) {
expectAssignable<MessageComponentInteraction>(interaction);
expectType<MessageActionRowComponent>(interaction.component);
expectType<Message<true>>(interaction.message);
expectType<Guild>(interaction.guild);
expectAssignable<Promise<Message>>(interaction.reply({ fetchReply: true }));
} else if (interaction.inRawGuild()) {
expectAssignable<MessageComponentInteraction>(interaction);
expectType<APIButtonComponent | APISelectMenuComponent>(interaction.component);
expectType<Message<false>>(interaction.message);
expectType<null>(interaction.guild);
expectType<Promise<Message<false>>>(interaction.reply({ fetchReply: true }));
} else if (interaction.inGuild()) {
expectAssignable<MessageComponentInteraction>(interaction);
expectType<MessageActionRowComponent | APIButtonComponent | APISelectMenuComponent>(interaction.component);
expectType<Message>(interaction.message);
expectType<Guild | null>(interaction.guild);
expectType<Promise<Message>>(interaction.reply({ fetchReply: true }));
}
}
if (interaction.isSelectMenu()) {
if (interaction.type === InteractionType.MessageComponent && interaction.componentType === ComponentType.SelectMenu) {
expectType<SelectMenuInteraction>(interaction);
expectType<SelectMenuComponent | APISelectMenuComponent>(interaction.component);
expectType<Message>(interaction.message);
@@ -1271,7 +1291,10 @@ client.on('interactionCreate', async interaction => {
}
}
if (interaction.isChatInputCommand()) {
if (
interaction.type === InteractionType.ApplicationCommand &&
interaction.commandType === ApplicationCommandType.ChatInput
) {
if (interaction.inRawGuild()) {
expectNotAssignable<Interaction<'cached'>>(interaction);
expectAssignable<ChatInputCommandInteraction>(interaction);
@@ -1334,7 +1357,11 @@ client.on('interactionCreate', async interaction => {
interaction.reply('test');
}
if (interaction.isChatInputCommand() && interaction.isRepliable()) {
if (
interaction.type === InteractionType.ApplicationCommand &&
interaction.commandType === ApplicationCommandType.ChatInput &&
interaction.isRepliable()
) {
expectAssignable<CommandInteraction>(interaction);
expectAssignable<InteractionResponseFields>(interaction);
}
@@ -1432,16 +1459,14 @@ declare const GuildBasedChannel: GuildBasedChannel;
declare const NonThreadGuildBasedChannel: NonThreadGuildBasedChannel;
declare const GuildTextBasedChannel: GuildTextBasedChannel;
expectType<DMChannel | PartialDMChannel | NewsChannel | TextChannel | ThreadChannel | VoiceChannel>(TextBasedChannel);
expectType<TextBasedChannel>(TextBasedChannel);
expectType<ChannelType.GuildText | ChannelType.DM | ChannelType.GuildNews | ChannelType.GuildVoice | ThreadChannelType>(
TextBasedChannelTypes,
);
expectType<StageChannel | VoiceChannel>(VoiceBasedChannel);
expectType<CategoryChannel | NewsChannel | StageChannel | TextChannel | ThreadChannel | VoiceChannel>(
GuildBasedChannel,
);
expectType<GuildBasedChannel>(GuildBasedChannel);
expectType<CategoryChannel | NewsChannel | StageChannel | TextChannel | VoiceChannel>(NonThreadGuildBasedChannel);
expectType<NewsChannel | TextChannel | ThreadChannel | VoiceChannel>(GuildTextBasedChannel);
expectType<GuildTextBasedChannel>(GuildTextBasedChannel);
const button = new ButtonBuilder({
label: 'test',