typings: cache types cleanup (#6867)

Co-authored-by: Almeida <almeidx@pm.me>
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
This commit is contained in:
Suneet Tipirneni
2021-10-27 06:08:01 -04:00
committed by GitHub
parent f169c8fe46
commit b2836daafe
2 changed files with 130 additions and 172 deletions

260
typings/index.d.ts vendored
View File

@@ -268,15 +268,16 @@ export class BaseClient extends EventEmitter {
public toJSON(...props: Record<string, boolean | string>[]): unknown; public toJSON(...props: Record<string, boolean | string>[]): unknown;
} }
export type GuildCacheMessage<Cached extends GuildCacheState> = CacheTypeReducer< export type GuildCacheMessage<Cached extends CacheType> = CacheTypeReducer<
Cached, Cached,
GuildMessage<Cached> & Message, Message<true>,
APIMessage, APIMessage,
Message | APIMessage, Message | APIMessage,
Message | APIMessage Message | APIMessage
>; >;
export abstract class BaseCommandInteraction extends Interaction { export abstract class BaseCommandInteraction<Cached extends CacheType = CacheType> extends Interaction<Cached> {
public options: CommandInteractionOptionResolver<Cached>;
public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null; public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null;
public readonly channel: TextBasedChannels | null; public readonly channel: TextBasedChannels | null;
public channelId: Snowflake; public channelId: Snowflake;
@@ -286,38 +287,26 @@ export abstract class BaseCommandInteraction extends Interaction {
public ephemeral: boolean | null; public ephemeral: boolean | null;
public replied: boolean; public replied: boolean;
public webhook: InteractionWebhook; public webhook: InteractionWebhook;
public inGuild(): this is InteractionResponses<'present'> & this; public inGuild(): this is BaseCommandInteraction<'present'> & this;
public inCachedGuild(): this is InteractionResponses<'cached'> & this; public inCachedGuild(): this is BaseCommandInteraction<'cached'> & this;
public inRawGuild(): this is InteractionResponses<'raw'> & this; public inRawGuild(): this is BaseCommandInteraction<'raw'> & this;
public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<Message | APIMessage>; public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<void>; public deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
public deleteReply(): Promise<void>; public deleteReply(): Promise<void>;
public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<Message | APIMessage>; public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<GuildCacheMessage<Cached>>;
public fetchReply(): Promise<Message | APIMessage>; public fetchReply(): Promise<GuildCacheMessage<Cached>>;
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<Message | APIMessage>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<GuildCacheMessage<Cached>>;
public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<Message | APIMessage>; public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
public reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>; public reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>;
private transformOption( private transformOption(
option: APIApplicationCommandOption, option: APIApplicationCommandOption,
resolved: APIApplicationCommandInteractionData['resolved'], resolved: APIApplicationCommandInteractionData['resolved'],
): CommandInteractionOption; ): CommandInteractionOption<Cached>;
private transformResolved(resolved: APIApplicationCommandInteractionData['resolved']): CommandInteractionResolvedData; private transformResolved(
resolved: APIApplicationCommandInteractionData['resolved'],
): CommandInteractionResolvedData<Cached>;
} }
export interface InteractionResponsesResolvable {
inGuild(): this is InteractionResponses<'present'> & this;
inCachedGuild(): this is InteractionResponses<'cached'> & this;
inRawGuild(): this is InteractionResponses<'raw'> & this;
}
export type CacheHelper<
T extends Interaction,
Cached extends GuildCacheState,
> = T extends InteractionResponsesResolvable ? InteractionResponses<Cached> & T : GuildInteraction<Cached> & T;
export type CachedInteraction<T extends Interaction = Interaction> = CacheHelper<T, 'cached'>;
export type RawInteraction<T extends Interaction = Interaction> = CacheHelper<T, 'raw'>;
export type PresentInteraction<T extends Interaction = Interaction> = CacheHelper<T, 'present'>;
export abstract class BaseGuild extends Base { export abstract class BaseGuild extends Base {
protected constructor(client: Client, data: RawBaseGuildData); protected constructor(client: Client, data: RawBaseGuildData);
public readonly createdAt: Date; public readonly createdAt: Date;
@@ -405,7 +394,7 @@ export class BitField<S extends string, N extends number | bigint = number> {
public static resolve(bit?: BitFieldResolvable<string, number | bigint>): number | bigint; public static resolve(bit?: BitFieldResolvable<string, number | bigint>): number | bigint;
} }
export class ButtonInteraction extends MessageComponentInteraction { export class ButtonInteraction<Cached extends CacheType = CacheType> extends MessageComponentInteraction<Cached> {
private constructor(client: Client, data: RawMessageButtonInteractionData); private constructor(client: Client, data: RawMessageButtonInteractionData);
public componentType: 'BUTTON'; public componentType: 'BUTTON';
} }
@@ -601,39 +590,33 @@ export abstract class Collector<K, V, F extends unknown[] = []> extends EventEmi
public once(event: 'end', listener: (collected: Collection<K, V>, reason: string) => Awaitable<void>): this; public once(event: 'end', listener: (collected: Collection<K, V>, reason: string) => Awaitable<void>): this;
} }
export type GuildCommandInteraction<Cached extends GuildCacheState> = InteractionResponses<Cached> & export class CommandInteraction<Cached extends CacheType = CacheType> extends BaseCommandInteraction<Cached> {
CommandInteraction<Cached>;
export class CommandInteraction<Cached extends GuildCacheState = GuildCacheState> extends BaseCommandInteraction {
public options: CommandInteractionOptionResolver<Cached>;
public inCachedGuild(): this is GuildCommandInteraction<'cached'> & this;
public inRawGuild(): this is GuildCommandInteraction<'raw'> & this;
public toString(): string; public toString(): string;
} }
export class CommandInteractionOptionResolver<Cached extends GuildCacheState = GuildCacheState> { export class CommandInteractionOptionResolver<Cached extends CacheType = CacheType> {
private constructor(client: Client, options: CommandInteractionOption[], resolved: CommandInteractionResolvedData); private constructor(client: Client, options: CommandInteractionOption[], resolved: CommandInteractionResolvedData);
public readonly client: Client; public readonly client: Client;
public readonly data: readonly CommandInteractionOption[]; public readonly data: readonly CommandInteractionOption<Cached>[];
public readonly resolved: Readonly<CommandInteractionResolvedData>; public readonly resolved: Readonly<CommandInteractionResolvedData<Cached>>;
private _group: string | null; private _group: string | null;
private _hoistedOptions: CommandInteractionOption[]; private _hoistedOptions: CommandInteractionOption<Cached>[];
private _subcommand: string | null; private _subcommand: string | null;
private _getTypedOption( private _getTypedOption(
name: string, name: string,
type: ApplicationCommandOptionType, type: ApplicationCommandOptionType,
properties: (keyof ApplicationCommandOption)[], properties: (keyof ApplicationCommandOption)[],
required: true, required: true,
): CommandInteractionOption; ): CommandInteractionOption<Cached>;
private _getTypedOption( private _getTypedOption(
name: string, name: string,
type: ApplicationCommandOptionType, type: ApplicationCommandOptionType,
properties: (keyof ApplicationCommandOption)[], properties: (keyof ApplicationCommandOption)[],
required: boolean, required: boolean,
): CommandInteractionOption | null; ): CommandInteractionOption<Cached> | null;
public get(name: string, required: true): CommandInteractionOption; public get(name: string, required: true): CommandInteractionOption<Cached>;
public get(name: string, required?: boolean): CommandInteractionOption | null; public get(name: string, required?: boolean): CommandInteractionOption<Cached> | null;
public getSubcommand(required?: true): string; public getSubcommand(required?: true): string;
public getSubcommand(required: boolean): string | null; public getSubcommand(required: boolean): string | null;
@@ -641,42 +624,35 @@ export class CommandInteractionOptionResolver<Cached extends GuildCacheState = G
public getSubcommandGroup(required: boolean): string | null; public getSubcommandGroup(required: boolean): string | null;
public getBoolean(name: string, required: true): boolean; public getBoolean(name: string, required: true): boolean;
public getBoolean(name: string, required?: boolean): boolean | null; public getBoolean(name: string, required?: boolean): boolean | null;
public getChannel(name: string, required: true): NonNullable<CommandInteractionOption['channel']>; public getChannel(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['channel']>;
public getChannel(name: string, required?: boolean): NonNullable<CommandInteractionOption['channel']> | null; public getChannel(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['channel']> | null;
public getString(name: string, required: true): string; public getString(name: string, required: true): string;
public getString(name: string, required?: boolean): string | null; public getString(name: string, required?: boolean): string | null;
public getInteger(name: string, required: true): number; public getInteger(name: string, required: true): number;
public getInteger(name: string, required?: boolean): number | null; public getInteger(name: string, required?: boolean): number | null;
public getNumber(name: string, required: true): number; public getNumber(name: string, required: true): number;
public getNumber(name: string, required?: boolean): number | null; public getNumber(name: string, required?: boolean): number | null;
public getUser(name: string, required: true): NonNullable<CommandInteractionOption['user']>; public getUser(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['user']>;
public getUser(name: string, required?: boolean): NonNullable<CommandInteractionOption['user']> | null; public getUser(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['user']> | null;
public getMember( public getMember(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['member']>;
name: string, public getMember(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['member']> | null;
required: true, public getRole(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['role']>;
): CacheTypeReducer<Cached, GuildMember, NonNullable<APIInteractionDataResolvedGuildMember>>; public getRole(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['role']> | null;
public getMember(
name: string,
required?: boolean,
): CacheTypeReducer<Cached, GuildMember, NonNullable<APIInteractionDataResolvedGuildMember>> | null;
public getRole(name: string, required: true): NonNullable<CommandInteractionOption['role']>;
public getRole(name: string, required?: boolean): NonNullable<CommandInteractionOption['role']> | null;
public getMentionable( public getMentionable(
name: string, name: string,
required: true, required: true,
): NonNullable<CommandInteractionOption['member' | 'role' | 'user']>; ): NonNullable<CommandInteractionOption<Cached>['member' | 'role' | 'user']>;
public getMentionable( public getMentionable(
name: string, name: string,
required?: boolean, required?: boolean,
): NonNullable<CommandInteractionOption['member' | 'role' | 'user']> | null; ): NonNullable<CommandInteractionOption<Cached>['member' | 'role' | 'user']> | null;
public getMessage(name: string, required: true): NonNullable<CommandInteractionOption['message']>; public getMessage(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['message']>;
public getMessage(name: string, required?: boolean): NonNullable<CommandInteractionOption['message']> | null; public getMessage(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['message']> | null;
} }
export class ContextMenuInteraction extends BaseCommandInteraction { export class ContextMenuInteraction<Cached extends CacheType = CacheType> extends BaseCommandInteraction<Cached> {
public options: CommandInteractionOptionResolver;
public targetId: Snowflake; public targetId: Snowflake;
public targetType: Exclude<ApplicationCommandType, 'CHAT_INPUT'>; public targetType: Exclude<ApplicationCommandType, 'CHAT_INPUT'>;
private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption[]; private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption<Cached>[];
} }
export class DataResolver extends null { export class DataResolver extends null {
@@ -1080,10 +1056,10 @@ export class Intents extends BitField<IntentsString> {
public static resolve(bit?: BitFieldResolvable<IntentsString, number>): number; public static resolve(bit?: BitFieldResolvable<IntentsString, number>): number;
} }
export type GuildCacheState = 'cached' | 'raw' | 'present'; export type CacheType = 'cached' | 'raw' | 'present';
export type CacheTypeReducer< export type CacheTypeReducer<
State extends GuildCacheState, State extends CacheType,
CachedType, CachedType,
RawType = CachedType, RawType = CachedType,
PresentType = CachedType | RawType, PresentType = CachedType | RawType,
@@ -1096,51 +1072,33 @@ export type CacheTypeReducer<
? PresentType ? PresentType
: Fallback; : Fallback;
export interface GuildInteraction<Cached extends GuildCacheState = GuildCacheState> extends Interaction { export class Interaction<Cached extends CacheType = CacheType> extends Base {
guildId: Snowflake; // This a technique used to brand different cached types. Or else we'll get `never` errors on typeguard checks.
member: CacheTypeReducer<Cached, GuildMember, APIInteractionGuildMember>; private readonly _cacheType: Cached;
readonly guild: CacheTypeReducer<Cached, Guild, null>;
channel: CacheTypeReducer<Cached, Exclude<TextBasedChannels, PartialDMChannel | DMChannel> | null>;
isCommand(): this is GuildCommandInteraction<Cached> & this;
}
export class Interaction extends Base {
protected constructor(client: Client, data: RawInteractionData); protected constructor(client: Client, data: RawInteractionData);
public applicationId: Snowflake; public applicationId: Snowflake;
public readonly channel: TextBasedChannels | null; public channel: CacheTypeReducer<Cached, TextBasedChannels | null>;
public channelId: Snowflake | null; public channelId: Snowflake | null;
public readonly createdAt: Date; public readonly createdAt: Date;
public readonly createdTimestamp: number; public readonly createdTimestamp: number;
public readonly guild: Guild | null; public readonly guild: CacheTypeReducer<Cached, Guild, null>;
public guildId: Snowflake | null; public guildId: CacheTypeReducer<Cached, Snowflake>;
public id: Snowflake; public id: Snowflake;
public member: GuildMember | APIInteractionGuildMember | null; public member: CacheTypeReducer<Cached, GuildMember, APIInteractionGuildMember>;
public readonly token: string; public readonly token: string;
public type: InteractionType; public type: InteractionType;
public user: User; public user: User;
public version: number; public version: number;
public memberPermissions: Readonly<Permissions> | null; public memberPermissions: Readonly<Permissions> | null;
public inGuild(): this is GuildInteraction<'present'> & this; public inGuild(): this is Interaction<'present'> & this;
public inCachedGuild(): this is GuildInteraction<'cached'> & this; public inCachedGuild(): this is Interaction<'cached'> & this;
public inRawGuild(): this is GuildInteraction<'raw'> & this; public inRawGuild(): this is Interaction<'raw'> & this;
public isApplicationCommand(): this is BaseCommandInteraction; public isApplicationCommand(): this is BaseCommandInteraction<Cached>;
public isButton(): this is ButtonInteraction; public isButton(): this is ButtonInteraction<Cached>;
public isCommand(): this is CommandInteraction; public isCommand(): this is CommandInteraction<Cached>;
public isContextMenu(): this is ContextMenuInteraction; public isContextMenu(): this is ContextMenuInteraction<Cached>;
public isMessageComponent(): this is MessageComponentInteraction; public isMessageComponent(): this is MessageComponentInteraction<Cached>;
public isSelectMenu(): this is SelectMenuInteraction; public isSelectMenu(): this is SelectMenuInteraction<Cached>;
}
export interface InteractionResponses<Cached extends GuildCacheState = GuildCacheState>
extends GuildInteraction<Cached> {
deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<GuildCacheMessage<Cached>>;
deleteReply(): Promise<void>;
fetchReply(): Promise<GuildCacheMessage<Cached>>;
reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>;
followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<GuildCacheMessage<Cached>>;
} }
export class InteractionCollector<T extends Interaction> extends Collector<Snowflake, T> { export class InteractionCollector<T extends Interaction> extends Collector<Snowflake, T> {
@@ -1268,10 +1226,11 @@ export type InteractionCollectorReturnType<
? ConditionalInteractionCollectorType<MappedInteractionCollectorOptions<Cached>[T]> ? ConditionalInteractionCollectorType<MappedInteractionCollectorOptions<Cached>[T]>
: InteractionCollector<MessageComponentInteraction>; : InteractionCollector<MessageComponentInteraction>;
export type InteractionExtractor<T extends MessageComponentType | MessageComponentTypes | undefined> = T extends export type InteractionExtractor<
| MessageComponentType T extends MessageComponentType | MessageComponentTypes | undefined,
| MessageComponentTypes C extends boolean = false,
? MappedInteractionCollectorOptions<false>[T] extends InteractionCollectorOptions<infer Item> > = T extends MessageComponentType | MessageComponentTypes
? MappedInteractionCollectorOptions<C>[T] extends InteractionCollectorOptions<infer Item>
? Item ? Item
: never : never
: MessageComponentInteraction; : MessageComponentInteraction;
@@ -1289,22 +1248,8 @@ export type AwaitMessageCollectorOptionsParams<T extends MessageComponentType |
export type GuildTextBasedChannel = Exclude<TextBasedChannels, PartialDMChannel | DMChannel>; export type GuildTextBasedChannel = Exclude<TextBasedChannels, PartialDMChannel | DMChannel>;
export type CachedMessage = GuildMessage<'cached'> & Message; export class Message<Cached extends boolean = boolean> extends Base {
export interface GuildMessage<Cached extends GuildCacheState = GuildCacheState> { private readonly _cacheType: Cached;
awaitMessageComponent<
T extends MessageComponentType | MessageComponentTypes | undefined = MessageComponentTypes.ACTION_ROW,
>(
options?: AwaitMessageCollectorOptionsParams<T>,
): Promise<InteractionResponses<Cached> & InteractionExtractor<T>>;
createMessageComponentCollector<T extends MessageComponentType | MessageComponentTypes | undefined = undefined>(
options?: MessageCollectorOptionsParams<T>,
): InteractionCollectorReturnType<T, true>;
readonly channel: CacheTypeReducer<Cached, GuildTextBasedChannel>;
}
export class Message extends Base {
private constructor(client: Client, data: RawMessageData); private constructor(client: Client, data: RawMessageData);
private _patch(data: RawPartialMessageData | RawMessageData): void; private _patch(data: RawPartialMessageData | RawMessageData): void;
@@ -1312,7 +1257,7 @@ export class Message extends Base {
public applicationId: Snowflake | null; public applicationId: Snowflake | null;
public attachments: Collection<Snowflake, MessageAttachment>; public attachments: Collection<Snowflake, MessageAttachment>;
public author: User; public author: User;
public readonly channel: TextBasedChannels; public readonly channel: If<Cached, GuildTextBasedChannel, TextBasedChannels>;
public channelId: Snowflake; public channelId: Snowflake;
public readonly cleanContent: string; public readonly cleanContent: string;
public components: MessageActionRow[]; public components: MessageActionRow[];
@@ -1350,12 +1295,12 @@ export class Message extends Base {
public reference: MessageReference | null; public reference: MessageReference | null;
public awaitMessageComponent< public awaitMessageComponent<
T extends MessageComponentType | MessageComponentTypes | undefined = MessageComponentTypes.ACTION_ROW, T extends MessageComponentType | MessageComponentTypes | undefined = MessageComponentTypes.ACTION_ROW,
>(options?: AwaitMessageCollectorOptionsParams<T>): Promise<InteractionExtractor<T>>; >(options?: AwaitMessageCollectorOptionsParams<T>): Promise<InteractionExtractor<T, Cached>>;
public awaitReactions(options?: AwaitReactionsOptions): Promise<Collection<Snowflake | string, MessageReaction>>; public awaitReactions(options?: AwaitReactionsOptions): Promise<Collection<Snowflake | string, MessageReaction>>;
public createReactionCollector(options?: ReactionCollectorOptions): ReactionCollector; public createReactionCollector(options?: ReactionCollectorOptions): ReactionCollector;
public createMessageComponentCollector< public createMessageComponentCollector<
T extends MessageComponentType | MessageComponentTypes | undefined = undefined, T extends MessageComponentType | MessageComponentTypes | undefined = undefined,
>(options?: MessageCollectorOptionsParams<T>): InteractionCollectorReturnType<T>; >(options?: MessageCollectorOptionsParams<T>): InteractionCollectorReturnType<T, Cached>;
public delete(): Promise<Message>; public delete(): Promise<Message>;
public edit(content: string | MessageEditOptions | MessagePayload): Promise<Message>; public edit(content: string | MessageEditOptions | MessagePayload): Promise<Message>;
public equals(message: Message, rawData: unknown): boolean; public equals(message: Message, rawData: unknown): boolean;
@@ -1373,7 +1318,7 @@ export class Message extends Base {
public toJSON(): unknown; public toJSON(): unknown;
public toString(): string; public toString(): string;
public unpin(): Promise<Message>; public unpin(): Promise<Message>;
public inGuild(): this is GuildMessage<'cached'> & this; public inGuild(): this is Message<true> & this;
} }
export class MessageActionRow extends BaseMessageComponent { export class MessageActionRow extends BaseMessageComponent {
@@ -1447,32 +1392,36 @@ export class MessageCollector extends Collector<Snowflake, Message> {
public dispose(message: Message): Snowflake | null; public dispose(message: Message): Snowflake | null;
} }
export class MessageComponentInteraction extends Interaction { export class MessageComponentInteraction<Cached extends CacheType = CacheType> extends Interaction<Cached> {
protected constructor(client: Client, data: RawMessageComponentInteractionData); protected constructor(client: Client, data: RawMessageComponentInteractionData);
public readonly channel: TextBasedChannels | null; public readonly channel: CacheTypeReducer<Cached, TextBasedChannels | null>;
public readonly component: MessageActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent>; public readonly component: CacheTypeReducer<
Cached,
MessageActionRowComponent,
Exclude<APIMessageComponent, APIActionRowComponent>
> | null;
public componentType: Exclude<MessageComponentType, 'ACTION_ROW'>; public componentType: Exclude<MessageComponentType, 'ACTION_ROW'>;
public customId: string; public customId: string;
public channelId: Snowflake; public channelId: Snowflake;
public deferred: boolean; public deferred: boolean;
public ephemeral: boolean | null; public ephemeral: boolean | null;
public message: Message | APIMessage; public message: CacheTypeReducer<Cached, Message, APIMessage>;
public replied: boolean; public replied: boolean;
public webhook: InteractionWebhook; public webhook: InteractionWebhook;
public inGuild(): this is InteractionResponses<'present'> & this; public inGuild(): this is MessageComponentInteraction<'present'> & this;
public inCachedGuild(): this is InteractionResponses<'cached'> & this; public inCachedGuild(): this is MessageComponentInteraction<'cached'> & this;
public inRawGuild(): this is InteractionResponses<'raw'> & this; public inRawGuild(): this is MessageComponentInteraction<'raw'> & this;
public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<Message | APIMessage>; public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<void>; public deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
public deferUpdate(options: InteractionDeferUpdateOptions & { fetchReply: true }): Promise<Message | APIMessage>; public deferUpdate(options: InteractionDeferUpdateOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
public deferUpdate(options?: InteractionDeferUpdateOptions): Promise<void>; public deferUpdate(options?: InteractionDeferUpdateOptions): Promise<void>;
public deleteReply(): Promise<void>; public deleteReply(): Promise<void>;
public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<Message | APIMessage>; public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<GuildCacheMessage<Cached>>;
public fetchReply(): Promise<Message | APIMessage>; public fetchReply(): Promise<GuildCacheMessage<Cached>>;
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<Message | APIMessage>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<GuildCacheMessage<Cached>>;
public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<Message | APIMessage>; public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
public reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>; public reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>;
public update(options: InteractionUpdateOptions & { fetchReply: true }): Promise<Message | APIMessage>; public update(options: InteractionUpdateOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
public update(options: string | MessagePayload | InteractionUpdateOptions): Promise<void>; public update(options: string | MessagePayload | InteractionUpdateOptions): Promise<void>;
public static resolveType(type: MessageComponentTypeResolvable): MessageComponentType; public static resolveType(type: MessageComponentTypeResolvable): MessageComponentType;
@@ -1767,7 +1716,7 @@ export class Role extends Base {
public static comparePositions(role1: Role, role2: Role): number; public static comparePositions(role1: Role, role2: Role): number;
} }
export class SelectMenuInteraction extends MessageComponentInteraction { export class SelectMenuInteraction<Cached extends CacheType = CacheType> extends MessageComponentInteraction<Cached> {
public constructor(client: Client, data: RawMessageSelectMenuInteractionData); public constructor(client: Client, data: RawMessageSelectMenuInteractionData);
public componentType: 'SELECT_MENU'; public componentType: 'SELECT_MENU';
public values: string[]; public values: string[];
@@ -3681,24 +3630,24 @@ export type ColorResolvable =
| number | number
| HexColorString; | HexColorString;
export interface CommandInteractionOption { export interface CommandInteractionOption<Cached extends CacheType = CacheType> {
name: string; name: string;
type: ApplicationCommandOptionType; type: ApplicationCommandOptionType;
value?: string | number | boolean; value?: string | number | boolean;
options?: CommandInteractionOption[]; options?: CommandInteractionOption[];
user?: User; user?: User;
member?: GuildMember | APIInteractionDataResolvedGuildMember; member?: CacheTypeReducer<Cached, GuildMember, APIInteractionDataResolvedGuildMember>;
channel?: GuildChannel | ThreadChannel | APIInteractionDataResolvedChannel; channel?: CacheTypeReducer<Cached, GuildChannel | ThreadChannel, APIInteractionDataResolvedChannel>;
role?: Role | APIRole; role?: CacheTypeReducer<Cached, Role, APIRole>;
message?: Message | APIMessage; message?: CacheTypeReducer<Cached, Message, APIMessage>;
} }
export interface CommandInteractionResolvedData { export interface CommandInteractionResolvedData<Cached extends CacheType = CacheType> {
users?: Collection<Snowflake, User>; users?: Collection<Snowflake, User>;
members?: Collection<Snowflake, GuildMember | APIInteractionDataResolvedGuildMember>; members?: Collection<Snowflake, CacheTypeReducer<Cached, GuildMember, APIInteractionDataResolvedGuildMember>>;
roles?: Collection<Snowflake, Role | APIRole>; roles?: Collection<Snowflake, CacheTypeReducer<Cached, Role, APIRole>>;
channels?: Collection<Snowflake, Channel | APIInteractionDataResolvedChannel>; channels?: Collection<Snowflake, CacheTypeReducer<Cached, Channel, APIInteractionDataResolvedChannel>>;
messages?: Collection<Snowflake, Message | APIMessage>; messages?: Collection<Snowflake, CacheTypeReducer<Cached, Message, APIMessage>>;
} }
export interface ConstantsClientApplicationAssetTypes { export interface ConstantsClientApplicationAssetTypes {
@@ -4263,7 +4212,8 @@ export interface IntegrationAccount {
export type IntegrationType = 'twitch' | 'youtube' | 'discord'; export type IntegrationType = 'twitch' | 'youtube' | 'discord';
export interface InteractionCollectorOptions<T extends Interaction> extends CollectorOptions<[T]> { export interface InteractionCollectorOptions<T extends Interaction, Cached extends CacheType = CacheType>
extends CollectorOptions<[T]> {
channel?: TextBasedChannels; channel?: TextBasedChannels;
componentType?: MessageComponentType | MessageComponentTypes; componentType?: MessageComponentType | MessageComponentTypes;
guild?: Guild; guild?: Guild;
@@ -4271,26 +4221,24 @@ export interface InteractionCollectorOptions<T extends Interaction> extends Coll
max?: number; max?: number;
maxComponents?: number; maxComponents?: number;
maxUsers?: number; maxUsers?: number;
message?: Message | APIMessage; message?: CacheTypeReducer<Cached, Message, APIMessage>;
} }
export interface ButtonInteractionCollectorOptions<Cached = boolean> export interface ButtonInteractionCollectorOptions<Cached = boolean>
extends MessageComponentCollectorOptions< extends MessageComponentCollectorOptions<Cached extends true ? ButtonInteraction<'cached'> : ButtonInteraction> {
Cached extends true ? CachedInteraction<ButtonInteraction> : ButtonInteraction
> {
componentType: 'BUTTON' | MessageComponentTypes.BUTTON; componentType: 'BUTTON' | MessageComponentTypes.BUTTON;
} }
export interface SelectMenuInteractionCollectorOptions<Cached = boolean> export interface SelectMenuInteractionCollectorOptions<Cached = boolean>
extends MessageComponentCollectorOptions< extends MessageComponentCollectorOptions<
Cached extends true ? CachedInteraction<SelectMenuInteraction> : SelectMenuInteraction Cached extends true ? SelectMenuInteraction<'cached'> : SelectMenuInteraction
> { > {
componentType: 'SELECT_MENU' | MessageComponentTypes.SELECT_MENU; componentType: 'SELECT_MENU' | MessageComponentTypes.SELECT_MENU;
} }
export interface MessageInteractionCollectorOptions<Cached = boolean> export interface MessageInteractionCollectorOptions<Cached = boolean>
extends MessageComponentCollectorOptions< extends MessageComponentCollectorOptions<
Cached extends true ? CachedInteraction<MessageComponentInteraction> : MessageComponentInteraction Cached extends true ? MessageComponentInteraction<'cached'> : MessageComponentInteraction
> { > {
componentType: 'ACTION_ROW' | MessageComponentTypes.ACTION_ROW; componentType: 'ACTION_ROW' | MessageComponentTypes.ACTION_ROW;
} }

View File

@@ -5,6 +5,8 @@ import {
APIPartialChannel, APIPartialChannel,
APIPartialGuild, APIPartialGuild,
APIInteractionDataResolvedGuildMember, APIInteractionDataResolvedGuildMember,
APIInteractionDataResolvedChannel,
APIRole,
} from 'discord-api-types/v9'; } from 'discord-api-types/v9';
import { import {
ApplicationCommand, ApplicationCommand,
@@ -33,19 +35,17 @@ import {
DMChannel, DMChannel,
Guild, Guild,
GuildApplicationCommandManager, GuildApplicationCommandManager,
CachedInteraction, GuildChannel,
GuildChannelManager, GuildChannelManager,
GuildEmoji, GuildEmoji,
GuildEmojiManager, GuildEmojiManager,
GuildMember, GuildMember,
GuildMessage,
GuildResolvable, GuildResolvable,
GuildTextBasedChannel, GuildTextBasedChannel,
GuildTextChannelResolvable, GuildTextChannelResolvable,
Intents, Intents,
Interaction, Interaction,
InteractionCollector, InteractionCollector,
InteractionResponses,
LimitedCollection, LimitedCollection,
Message, Message,
MessageActionRow, MessageActionRow,
@@ -77,7 +77,6 @@ import {
Typing, Typing,
User, User,
VoiceChannel, VoiceChannel,
CachedMessage,
} from '.'; } from '.';
import { ApplicationCommandOptionTypes } from './enums'; import { ApplicationCommandOptionTypes } from './enums';
@@ -498,13 +497,13 @@ client.on('messageCreate', async message => {
assertIsMessage(channel.send({ embeds: [embed], files: [attachment] })); assertIsMessage(channel.send({ embeds: [embed], files: [attachment] }));
if (message.inGuild()) { if (message.inGuild()) {
assertType<CachedMessage>(message); assertType<Message<true>>(message);
const component = await message.awaitMessageComponent({ componentType: 'BUTTON' }); const component = await message.awaitMessageComponent({ componentType: 'BUTTON' });
assertType<InteractionResponses<'cached'>>(component); assertType<ButtonInteraction<'cached'>>(component);
assertType<Promise<CachedMessage>>(component.reply({ fetchReply: true })); assertType<Message<true>>(await component.reply({ fetchReply: true }));
const buttonCollector = message.createMessageComponentCollector({ componentType: 'BUTTON' }); const buttonCollector = message.createMessageComponentCollector({ componentType: 'BUTTON' });
assertType<InteractionCollector<CachedInteraction<ButtonInteraction>>>(buttonCollector); assertType<InteractionCollector<ButtonInteraction<'cached'>>>(buttonCollector);
assertType<GuildTextBasedChannel>(message.channel); assertType<GuildTextBasedChannel>(message.channel);
} }
@@ -897,14 +896,11 @@ declare const booleanValue: boolean;
if (interaction.inGuild()) assertType<Snowflake>(interaction.guildId); if (interaction.inGuild()) assertType<Snowflake>(interaction.guildId);
client.on('interactionCreate', async interaction => { client.on('interactionCreate', async interaction => {
const consumeCachedCommand = (_i: CachedInteraction<CommandInteraction>) => {};
const consumeCachedInteraction = (_i: CachedInteraction<Interaction>) => {};
if (interaction.inCachedGuild()) { if (interaction.inCachedGuild()) {
assertType<GuildMember>(interaction.member); assertType<GuildMember>(interaction.member);
// @ts-expect-error // @ts-expect-error
consumeCachedCommand(interaction); assertType<CommandInteraction<'cached'>>(interaction);
consumeCachedInteraction(interaction); assertType<Interaction>(interaction);
} else if (interaction.inRawGuild()) { } else if (interaction.inRawGuild()) {
assertType<APIInteractionGuildMember>(interaction.member); assertType<APIInteractionGuildMember>(interaction.member);
// @ts-expect-error // @ts-expect-error
@@ -920,7 +916,7 @@ client.on('interactionCreate', async interaction => {
if (interaction.inCachedGuild()) { if (interaction.inCachedGuild()) {
assertType<ContextMenuInteraction>(interaction); assertType<ContextMenuInteraction>(interaction);
assertType<Guild>(interaction.guild); assertType<Guild>(interaction.guild);
consumeCachedCommand(interaction); assertType<CommandInteraction<'cached'>>(interaction);
} else if (interaction.inRawGuild()) { } else if (interaction.inRawGuild()) {
assertType<ContextMenuInteraction>(interaction); assertType<ContextMenuInteraction>(interaction);
assertType<null>(interaction.guild); assertType<null>(interaction.guild);
@@ -989,18 +985,26 @@ client.on('interactionCreate', async interaction => {
assertType<Promise<APIMessage>>(interaction.reply({ fetchReply: true })); assertType<Promise<APIMessage>>(interaction.reply({ fetchReply: true }));
assertType<APIInteractionDataResolvedGuildMember | null>(interaction.options.getMember('test')); assertType<APIInteractionDataResolvedGuildMember | null>(interaction.options.getMember('test'));
assertType<APIInteractionDataResolvedGuildMember>(interaction.options.getMember('test', true)); assertType<APIInteractionDataResolvedGuildMember>(interaction.options.getMember('test', true));
assertType<APIInteractionDataResolvedChannel>(interaction.options.getChannel('test', true));
assertType<APIRole>(interaction.options.getRole('test', true));
assertType<APIMessage>(interaction.options.getMessage('test', true));
} else if (interaction.inCachedGuild()) { } else if (interaction.inCachedGuild()) {
const msg = await interaction.reply({ fetchReply: true }); const msg = await interaction.reply({ fetchReply: true });
const btn = await msg.awaitMessageComponent({ componentType: 'BUTTON' }); const btn = await msg.awaitMessageComponent({ componentType: 'BUTTON' });
assertType<Message>(msg); assertType<Message>(msg);
assertType<CachedInteraction<ButtonInteraction>>(btn); assertType<ButtonInteraction<'cached'>>(btn);
consumeCachedCommand(interaction); assertType<CommandInteraction<'cached'>>(interaction);
assertType<GuildMember>(interaction.options.getMember('test', true)); assertType<GuildMember>(interaction.options.getMember('test', true));
assertType<GuildMember | null>(interaction.options.getMember('test')); assertType<GuildMember | null>(interaction.options.getMember('test'));
assertType<CommandInteraction>(interaction); assertType<CommandInteraction>(interaction);
assertType<Promise<Message>>(interaction.reply({ fetchReply: true })); assertType<Promise<Message>>(interaction.reply({ fetchReply: true }));
assertType<GuildChannel | ThreadChannel>(interaction.options.getChannel('test', true));
assertType<Role>(interaction.options.getRole('test', true));
assertType<Message>(interaction.options.getMessage('test', true));
} else { } else {
// @ts-expect-error // @ts-expect-error
consumeCachedCommand(interaction); consumeCachedCommand(interaction);
@@ -1008,6 +1012,12 @@ client.on('interactionCreate', async interaction => {
assertType<Promise<Message | APIMessage>>(interaction.reply({ fetchReply: true })); assertType<Promise<Message | APIMessage>>(interaction.reply({ fetchReply: true }));
assertType<APIInteractionDataResolvedGuildMember | GuildMember | null>(interaction.options.getMember('test')); assertType<APIInteractionDataResolvedGuildMember | GuildMember | null>(interaction.options.getMember('test'));
assertType<APIInteractionDataResolvedGuildMember | GuildMember>(interaction.options.getMember('test', true)); assertType<APIInteractionDataResolvedGuildMember | GuildMember>(interaction.options.getMember('test', true));
assertType<GuildChannel | ThreadChannel | APIInteractionDataResolvedChannel>(
interaction.options.getChannel('test', true),
);
assertType<APIRole | Role>(interaction.options.getRole('test', true));
assertType<APIMessage | Message>(interaction.options.getMessage('test', true));
} }
assertType<CommandInteraction>(interaction); assertType<CommandInteraction>(interaction);