types: make channel types a lot stricter (#7120)

This commit is contained in:
Antonio Román
2021-12-22 11:13:01 +01:00
committed by GitHub
parent 6bb03f2c34
commit 7b65a04cb1
2 changed files with 114 additions and 86 deletions

160
typings/index.d.ts vendored
View File

@@ -386,7 +386,7 @@ export class BaseGuildEmoji extends Emoji {
public requiresColons: boolean | null; public requiresColons: boolean | null;
} }
export class BaseGuildTextChannel extends TextBasedChannel(GuildChannel) { export class BaseGuildTextChannel extends TextBasedChannelMixin(GuildChannel) {
protected constructor(guild: Guild, data?: RawGuildChannelData, client?: Client, immediatePatch?: boolean); protected constructor(guild: Guild, data?: RawGuildChannelData, client?: Client, immediatePatch?: boolean);
public defaultAutoArchiveDuration?: ThreadAutoArchiveDuration; public defaultAutoArchiveDuration?: ThreadAutoArchiveDuration;
public messages: MessageManager; public messages: MessageManager;
@@ -492,7 +492,7 @@ export type CategoryChannelTypes = ExcludeEnum<
>; >;
export class CategoryChannel extends GuildChannel { export class CategoryChannel extends GuildChannel {
public readonly children: Collection<Snowflake, GuildChannel>; public readonly children: Collection<Snowflake, Exclude<NonThreadGuildBasedChannel, CategoryChannel>>;
public type: 'GUILD_CATEGORY'; public type: 'GUILD_CATEGORY';
/** @deprecated See [Self-serve Game Selling Deprecation](https://support-dev.discord.com/hc/en-us/articles/4414590563479) for more information */ /** @deprecated See [Self-serve Game Selling Deprecation](https://support-dev.discord.com/hc/en-us/articles/4414590563479) for more information */
public createChannel( public createChannel(
@@ -507,7 +507,7 @@ export class CategoryChannel extends GuildChannel {
public createChannel( public createChannel(
name: string, name: string,
options: CategoryCreateChannelOptions, options: CategoryCreateChannelOptions,
): Promise<TextChannel | VoiceChannel | NewsChannel | StoreChannel | StageChannel>; ): Promise<Exclude<NonThreadGuildBasedChannel, CategoryChannel>>;
} }
export type CategoryChannelResolvable = Snowflake | CategoryChannel; export type CategoryChannelResolvable = Snowflake | CategoryChannel;
@@ -521,9 +521,9 @@ export abstract class Channel extends Base {
public id: Snowflake; public id: Snowflake;
public readonly partial: false; public readonly partial: false;
public type: keyof typeof ChannelTypes; public type: keyof typeof ChannelTypes;
public delete(): Promise<Channel>; public delete(): Promise<this>;
public fetch(force?: boolean): Promise<Channel>; public fetch(force?: boolean): Promise<this>;
public isText(): this is TextBasedChannels; public isText(): this is TextBasedChannel;
public isVoice(): this is BaseGuildVoiceChannel; public isVoice(): this is BaseGuildVoiceChannel;
public isThread(): this is ThreadChannel; public isThread(): this is ThreadChannel;
public toString(): ChannelMention; public toString(): ChannelMention;
@@ -842,7 +842,7 @@ export class DiscordAPIError extends Error {
public requestData: HTTPErrorData; public requestData: HTTPErrorData;
} }
export class DMChannel extends TextBasedChannel(Channel, ['bulkDelete']) { export class DMChannel extends TextBasedChannelMixin(Channel, ['bulkDelete']) {
private constructor(client: Client, data?: RawDMChannelData); private constructor(client: Client, data?: RawDMChannelData);
public messages: MessageManager; public messages: MessageManager;
public recipient: User; public recipient: User;
@@ -868,7 +868,7 @@ export class Emoji extends Base {
export class Guild extends AnonymousGuild { export class Guild extends AnonymousGuild {
private constructor(client: Client, data: RawGuildData); private constructor(client: Client, data: RawGuildData);
private _sortedRoles(): Collection<Snowflake, Role>; private _sortedRoles(): Collection<Snowflake, Role>;
private _sortedChannels(channel: Channel): Collection<Snowflake, GuildChannel>; private _sortedChannels(channel: NonThreadGuildBasedChannel): Collection<Snowflake, NonThreadGuildBasedChannel>;
public readonly afkChannel: VoiceChannel | null; public readonly afkChannel: VoiceChannel | null;
public afkChannelId: Snowflake | null; public afkChannelId: Snowflake | null;
@@ -1255,7 +1255,7 @@ export class Interaction<Cached extends CacheType = CacheType> extends Base {
GuildTextBasedChannel | null, GuildTextBasedChannel | null,
GuildTextBasedChannel | null, GuildTextBasedChannel | null,
GuildTextBasedChannel | null, GuildTextBasedChannel | null,
TextBasedChannels | null TextBasedChannel | null
>; >;
public channelId: Snowflake | null; public channelId: Snowflake | null;
public readonly createdAt: Date; public readonly createdAt: Date;
@@ -1286,7 +1286,7 @@ export class Interaction<Cached extends CacheType = CacheType> extends Base {
export class InteractionCollector<T extends Interaction> extends Collector<Snowflake, T> { export class InteractionCollector<T extends Interaction> extends Collector<Snowflake, T> {
public constructor(client: Client, options?: InteractionCollectorOptions<T>); public constructor(client: Client, options?: InteractionCollectorOptions<T>);
private _handleMessageDeletion(message: Message): void; private _handleMessageDeletion(message: Message): void;
private _handleChannelDeletion(channel: GuildChannel): void; private _handleChannelDeletion(channel: NonThreadGuildBasedChannel): void;
private _handleGuildDeletion(guild: Guild): void; private _handleGuildDeletion(guild: Guild): void;
public channelId: Snowflake | null; public channelId: Snowflake | null;
@@ -1319,7 +1319,7 @@ export class InteractionWebhook extends PartialWebhookMixin() {
export class Invite extends Base { export class Invite extends Base {
private constructor(client: Client, data: RawInviteData); private constructor(client: Client, data: RawInviteData);
public channel: GuildChannel | PartialGroupDMChannel; public channel: NonThreadGuildBasedChannel | PartialGroupDMChannel;
public channelId: Snowflake; public channelId: Snowflake;
public code: string; public code: string;
public readonly deletable: boolean; public readonly deletable: boolean;
@@ -1399,7 +1399,6 @@ export type AwaitMessageCollectorOptionsParams<
keyof AwaitMessageComponentOptions<any> keyof AwaitMessageComponentOptions<any>
>; >;
export type GuildTextBasedChannel = Exclude<TextBasedChannels, PartialDMChannel | DMChannel>;
export interface StringMappedInteractionTypes<Cached extends CacheType = CacheType> { export interface StringMappedInteractionTypes<Cached extends CacheType = CacheType> {
BUTTON: ButtonInteraction<Cached>; BUTTON: ButtonInteraction<Cached>;
SELECT_MENU: SelectMenuInteraction<Cached>; SELECT_MENU: SelectMenuInteraction<Cached>;
@@ -1426,7 +1425,7 @@ export class Message<Cached extends boolean = boolean> 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: If<Cached, GuildTextBasedChannel, TextBasedChannels>; public readonly channel: If<Cached, GuildTextBasedChannel, TextBasedChannel>;
public channelId: Snowflake; public channelId: Snowflake;
public readonly cleanContent: string; public readonly cleanContent: string;
public components: MessageActionRow[]; public components: MessageActionRow[];
@@ -1551,11 +1550,11 @@ export class MessageButton extends BaseMessageComponent {
} }
export class MessageCollector extends Collector<Snowflake, Message> { export class MessageCollector extends Collector<Snowflake, Message> {
public constructor(channel: TextBasedChannels, options?: MessageCollectorOptions); public constructor(channel: TextBasedChannel, options?: MessageCollectorOptions);
private _handleChannelDeletion(channel: GuildChannel): void; private _handleChannelDeletion(channel: NonThreadGuildBasedChannel): void;
private _handleGuildDeletion(guild: Guild): void; private _handleGuildDeletion(guild: Guild): void;
public channel: TextBasedChannels; public channel: TextBasedChannel;
public readonly endReason: string | null; public readonly endReason: string | null;
public options: MessageCollectorOptions; public options: MessageCollectorOptions;
public received: number; public received: number;
@@ -1665,11 +1664,11 @@ export class MessageMentions {
everyone: boolean, everyone: boolean,
repliedUser?: APIUser | User, repliedUser?: APIUser | User,
); );
private _channels: Collection<Snowflake, Channel> | null; private _channels: Collection<Snowflake, TextBasedChannel> | null;
private readonly _content: string; private readonly _content: string;
private _members: Collection<Snowflake, GuildMember> | null; private _members: Collection<Snowflake, GuildMember> | null;
public readonly channels: Collection<Snowflake, Channel>; public readonly channels: Collection<Snowflake, TextBasedChannel>;
public readonly client: Client; public readonly client: Client;
public everyone: boolean; public everyone: boolean;
public readonly guild: Guild; public readonly guild: Guild;
@@ -1774,9 +1773,9 @@ export class PartialGroupDMChannel extends Channel {
} }
export class PermissionOverwrites extends Base { export class PermissionOverwrites extends Base {
private constructor(client: Client, data: RawPermissionOverwriteData, channel: GuildChannel); private constructor(client: Client, data: RawPermissionOverwriteData, channel: NonThreadGuildBasedChannel);
public allow: Readonly<Permissions>; public allow: Readonly<Permissions>;
public readonly channel: GuildChannel; public readonly channel: NonThreadGuildBasedChannel;
public deny: Readonly<Permissions>; public deny: Readonly<Permissions>;
public id: Snowflake; public id: Snowflake;
public type: OverwriteType; public type: OverwriteType;
@@ -1818,7 +1817,7 @@ export class Presence extends Base {
export class ReactionCollector extends Collector<Snowflake | string, MessageReaction, [User]> { export class ReactionCollector extends Collector<Snowflake | string, MessageReaction, [User]> {
public constructor(message: Message, options?: ReactionCollectorOptions); public constructor(message: Message, options?: ReactionCollectorOptions);
private _handleChannelDeletion(channel: GuildChannel): void; private _handleChannelDeletion(channel: NonThreadGuildBasedChannel): void;
private _handleGuildDeletion(guild: Guild): void; private _handleGuildDeletion(guild: Guild): void;
private _handleMessageDeletion(message: Message): void; private _handleMessageDeletion(message: Message): void;
@@ -1889,7 +1888,7 @@ export class Role extends Base {
public edit(data: RoleData, reason?: string): Promise<Role>; public edit(data: RoleData, reason?: string): Promise<Role>;
public equals(role: Role): boolean; public equals(role: Role): boolean;
public iconURL(options?: StaticImageURLOptions): string | null; public iconURL(options?: StaticImageURLOptions): string | null;
public permissionsIn(channel: GuildChannel | Snowflake, checkAdmin?: boolean): Readonly<Permissions>; public permissionsIn(channel: NonThreadGuildBasedChannel | Snowflake, checkAdmin?: boolean): Readonly<Permissions>;
public setColor(color: ColorResolvable, reason?: string): Promise<Role>; public setColor(color: ColorResolvable, reason?: string): Promise<Role>;
public setHoist(hoist?: boolean, reason?: string): Promise<Role>; public setHoist(hoist?: boolean, reason?: string): Promise<Role>;
public setMentionable(mentionable?: boolean, reason?: string): Promise<Role>; public setMentionable(mentionable?: boolean, reason?: string): Promise<Role>;
@@ -2226,7 +2225,7 @@ export class TextChannel extends BaseGuildTextChannel {
public setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise<TextChannel>; public setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise<TextChannel>;
} }
export class ThreadChannel extends TextBasedChannel(Channel) { export class ThreadChannel extends TextBasedChannelMixin(Channel) {
private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client, fromInteraction?: boolean); private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client, fromInteraction?: boolean);
public archived: boolean | null; public archived: boolean | null;
public readonly archivedAt: Date | null; public readonly archivedAt: Date | null;
@@ -2254,7 +2253,7 @@ export class ThreadChannel extends TextBasedChannel(Channel) {
public rateLimitPerUser: number | null; public rateLimitPerUser: number | null;
public type: ThreadChannelTypes; public type: ThreadChannelTypes;
public readonly unarchivable: boolean; public readonly unarchivable: boolean;
public delete(reason?: string): Promise<ThreadChannel>; public delete(reason?: string): Promise<this>;
public edit(data: ThreadEditData, reason?: string): Promise<ThreadChannel>; public edit(data: ThreadEditData, reason?: string): Promise<ThreadChannel>;
public join(): Promise<ThreadChannel>; public join(): Promise<ThreadChannel>;
public leave(): Promise<ThreadChannel>; public leave(): Promise<ThreadChannel>;
@@ -2295,8 +2294,8 @@ export class ThreadMemberFlags extends BitField<ThreadMemberFlagsString> {
} }
export class Typing extends Base { export class Typing extends Base {
private constructor(channel: TextBasedChannels, user: PartialUser, data?: RawTypingData); private constructor(channel: TextBasedChannel, user: PartialUser, data?: RawTypingData);
public channel: TextBasedChannels; public channel: TextBasedChannel;
public user: PartialUser; public user: PartialUser;
public startedTimestamp: number; public startedTimestamp: number;
public readonly startedAt: Date; public readonly startedAt: Date;
@@ -2357,7 +2356,7 @@ export class Util extends null {
/** @deprecated When not using with `makeCache` use `Sweepers.archivedThreadSweepFilter` instead */ /** @deprecated When not using with `makeCache` use `Sweepers.archivedThreadSweepFilter` instead */
public static archivedThreadSweepFilter<K, V>(lifetime?: number): SweepFilter<K, V>; public static archivedThreadSweepFilter<K, V>(lifetime?: number): SweepFilter<K, V>;
public static basename(path: string, ext?: string): string; public static basename(path: string, ext?: string): string;
public static cleanContent(str: string, channel: TextBasedChannels): string; public static cleanContent(str: string, channel: TextBasedChannel): string;
/** @deprecated Use {@link MessageOptions.allowedMentions} to control mentions in a message instead. */ /** @deprecated Use {@link MessageOptions.allowedMentions} to control mentions in a message instead. */
public static removeMentions(str: string): string; public static removeMentions(str: string): string;
public static cloneObject(obj: unknown): unknown; public static cloneObject(obj: unknown): unknown;
@@ -2383,7 +2382,7 @@ export class Util extends null {
public static resolveColor(color: ColorResolvable): number; public static resolveColor(color: ColorResolvable): number;
public static resolvePartialEmoji(emoji: EmojiIdentifierResolvable): Partial<APIPartialEmoji> | null; public static resolvePartialEmoji(emoji: EmojiIdentifierResolvable): Partial<APIPartialEmoji> | null;
public static verifyString(data: string, error?: typeof Error, errorMessage?: string, allowEmpty?: boolean): string; public static verifyString(data: string, error?: typeof Error, errorMessage?: string, allowEmpty?: boolean): string;
public static setPosition<T extends Channel | Role>( public static setPosition<T extends AnyChannel | Role>(
item: T, item: T,
position: number, position: number,
relative: boolean, relative: boolean,
@@ -2438,7 +2437,7 @@ export class VoiceRegion {
export class VoiceState extends Base { export class VoiceState extends Base {
private constructor(guild: Guild, data: RawVoiceStateData); private constructor(guild: Guild, data: RawVoiceStateData);
public readonly channel: VoiceChannel | StageChannel | null; public readonly channel: VoiceBasedChannel | null;
public channelId: Snowflake | null; public channelId: Snowflake | null;
public readonly deaf: boolean | null; public readonly deaf: boolean | null;
public guild: Guild; public guild: Guild;
@@ -2896,9 +2895,9 @@ export class BaseGuildEmojiManager extends CachedManager<Snowflake, GuildEmoji,
public resolveIdentifier(emoji: EmojiIdentifierResolvable): string | null; public resolveIdentifier(emoji: EmojiIdentifierResolvable): string | null;
} }
export class ChannelManager extends CachedManager<Snowflake, Channel, ChannelResolvable> { export class ChannelManager extends CachedManager<Snowflake, AnyChannel, ChannelResolvable> {
private constructor(client: Client, iterable: Iterable<RawChannelData>); private constructor(client: Client, iterable: Iterable<RawChannelData>);
public fetch(id: Snowflake, options?: FetchChannelOptions): Promise<Channel | null>; public fetch(id: Snowflake, options?: FetchChannelOptions): Promise<AnyChannel | null>;
} }
export class GuildApplicationCommandManager extends ApplicationCommandManager<ApplicationCommand, {}, Guild> { export class GuildApplicationCommandManager extends ApplicationCommandManager<ApplicationCommand, {}, Guild> {
@@ -2926,11 +2925,7 @@ export type MappedGuildChannelTypes = EnumValueMapped<
export type GuildChannelTypes = CategoryChannelTypes | ChannelTypes.GUILD_CATEGORY | 'GUILD_CATEGORY'; export type GuildChannelTypes = CategoryChannelTypes | ChannelTypes.GUILD_CATEGORY | 'GUILD_CATEGORY';
export class GuildChannelManager extends CachedManager< export class GuildChannelManager extends CachedManager<Snowflake, GuildBasedChannel, GuildChannelResolvable> {
Snowflake,
GuildChannel | ThreadChannel,
GuildChannelResolvable
> {
private constructor(guild: Guild, iterable?: Iterable<RawGuildChannelData>); private constructor(guild: Guild, iterable?: Iterable<RawGuildChannelData>);
public readonly channelCountWithoutThreads: number; public readonly channelCountWithoutThreads: number;
public guild: Guild; public guild: Guild;
@@ -2940,20 +2935,9 @@ export class GuildChannelManager extends CachedManager<
name: string, name: string,
options: GuildChannelCreateOptions & { type: T }, options: GuildChannelCreateOptions & { type: T },
): Promise<MappedGuildChannelTypes[T]>; ): Promise<MappedGuildChannelTypes[T]>;
public create( public create(name: string, options: GuildChannelCreateOptions): Promise<NonThreadGuildBasedChannel>;
name: string, public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<NonThreadGuildBasedChannel | null>;
options: GuildChannelCreateOptions, public fetch(id?: undefined, options?: BaseFetchOptions): Promise<Collection<Snowflake, NonThreadGuildBasedChannel>>;
): Promise<TextChannel | VoiceChannel | CategoryChannel | NewsChannel | StoreChannel | StageChannel>;
public fetch(
id: Snowflake,
options?: BaseFetchOptions,
): Promise<TextChannel | VoiceChannel | CategoryChannel | NewsChannel | StoreChannel | StageChannel | null>;
public fetch(
id?: undefined,
options?: BaseFetchOptions,
): Promise<
Collection<Snowflake, TextChannel | VoiceChannel | CategoryChannel | NewsChannel | StoreChannel | StageChannel>
>;
public setPositions(channelPositions: readonly ChannelPosition[]): Promise<Guild>; public setPositions(channelPositions: readonly ChannelPosition[]): Promise<Guild>;
public fetchActiveThreads(cache?: boolean): Promise<FetchedThreads>; public fetchActiveThreads(cache?: boolean): Promise<FetchedThreads>;
} }
@@ -3068,8 +3052,8 @@ export class GuildMemberRoleManager extends DataManager<Snowflake, Role, RoleRes
} }
export class MessageManager extends CachedManager<Snowflake, Message, MessageResolvable> { export class MessageManager extends CachedManager<Snowflake, Message, MessageResolvable> {
private constructor(channel: TextBasedChannels, iterable?: Iterable<RawMessageData>); private constructor(channel: TextBasedChannel, iterable?: Iterable<RawMessageData>);
public channel: TextBasedChannels; public channel: TextBasedChannel;
public cache: Collection<Snowflake, Message>; public cache: Collection<Snowflake, Message>;
public crosspost(message: MessageResolvable): Promise<Message>; public crosspost(message: MessageResolvable): Promise<Message>;
public delete(message: MessageResolvable): Promise<void>; public delete(message: MessageResolvable): Promise<void>;
@@ -3094,24 +3078,24 @@ export class PermissionOverwriteManager extends CachedManager<
public set( public set(
overwrites: readonly OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>, overwrites: readonly OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>,
reason?: string, reason?: string,
): Promise<GuildChannel>; ): Promise<NonThreadGuildBasedChannel>;
private upsert( private upsert(
userOrRole: RoleResolvable | UserResolvable, userOrRole: RoleResolvable | UserResolvable,
options: PermissionOverwriteOptions, options: PermissionOverwriteOptions,
overwriteOptions?: GuildChannelOverwriteOptions, overwriteOptions?: GuildChannelOverwriteOptions,
existing?: PermissionOverwrites, existing?: PermissionOverwrites,
): Promise<GuildChannel>; ): Promise<NonThreadGuildBasedChannel>;
public create( public create(
userOrRole: RoleResolvable | UserResolvable, userOrRole: RoleResolvable | UserResolvable,
options: PermissionOverwriteOptions, options: PermissionOverwriteOptions,
overwriteOptions?: GuildChannelOverwriteOptions, overwriteOptions?: GuildChannelOverwriteOptions,
): Promise<GuildChannel>; ): Promise<NonThreadGuildBasedChannel>;
public edit( public edit(
userOrRole: RoleResolvable | UserResolvable, userOrRole: RoleResolvable | UserResolvable,
options: PermissionOverwriteOptions, options: PermissionOverwriteOptions,
overwriteOptions?: GuildChannelOverwriteOptions, overwriteOptions?: GuildChannelOverwriteOptions,
): Promise<GuildChannel>; ): Promise<NonThreadGuildBasedChannel>;
public delete(userOrRole: RoleResolvable | UserResolvable, reason?: string): Promise<GuildChannel>; public delete(userOrRole: RoleResolvable | UserResolvable, reason?: string): Promise<NonThreadGuildBasedChannel>;
} }
export class PresenceManager extends CachedManager<Snowflake, Presence, PresenceResolvable> { export class PresenceManager extends CachedManager<Snowflake, Presence, PresenceResolvable> {
@@ -3196,7 +3180,7 @@ export class VoiceStateManager extends CachedManager<Snowflake, VoiceState, type
export type Constructable<T> = abstract new (...args: any[]) => T; export type Constructable<T> = abstract new (...args: any[]) => T;
export function PartialTextBasedChannel<T>(Base?: Constructable<T>): Constructable<T & PartialTextBasedChannelFields>; export function PartialTextBasedChannel<T>(Base?: Constructable<T>): Constructable<T & PartialTextBasedChannelFields>;
export function TextBasedChannel<T, I extends keyof TextBasedChannelFields = never>( export function TextBasedChannelMixin<T, I extends keyof TextBasedChannelFields = never>(
Base?: Constructable<T>, Base?: Constructable<T>,
ignore?: I[], ignore?: I[],
): Constructable<T & Omit<TextBasedChannelFields, I>>; ): Constructable<T & Omit<TextBasedChannelFields, I>>;
@@ -3789,14 +3773,14 @@ export interface ChannelLogsQueryOptions {
export type ChannelMention = `<#${Snowflake}>`; export type ChannelMention = `<#${Snowflake}>`;
export interface ChannelPosition { export interface ChannelPosition {
channel: GuildChannel | Snowflake; channel: NonThreadGuildBasedChannel | Snowflake;
lockPermissions?: boolean; lockPermissions?: boolean;
parent?: CategoryChannelResolvable | null; parent?: CategoryChannelResolvable | null;
position?: number; position?: number;
} }
export type GuildTextChannelResolvable = TextChannel | NewsChannel | Snowflake; export type GuildTextChannelResolvable = TextChannel | NewsChannel | Snowflake;
export type ChannelResolvable = Channel | Snowflake; export type ChannelResolvable = AnyChannel | Snowflake;
export interface ChannelWebhookCreateOptions { export interface ChannelWebhookCreateOptions {
avatar?: BufferResolvable | Base64Resolvable | null; avatar?: BufferResolvable | Base64Resolvable | null;
@@ -3819,10 +3803,13 @@ export interface ClientEvents extends BaseClientEvents {
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */ /** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
applicationCommandUpdate: [oldCommand: ApplicationCommand | null, newCommand: ApplicationCommand]; applicationCommandUpdate: [oldCommand: ApplicationCommand | null, newCommand: ApplicationCommand];
cacheSweep: [message: string]; cacheSweep: [message: string];
channelCreate: [channel: GuildChannel]; channelCreate: [channel: NonThreadGuildBasedChannel];
channelDelete: [channel: DMChannel | GuildChannel]; channelDelete: [channel: DMChannel | NonThreadGuildBasedChannel];
channelPinsUpdate: [channel: TextBasedChannels, date: Date]; channelPinsUpdate: [channel: TextBasedChannel, date: Date];
channelUpdate: [oldChannel: DMChannel | GuildChannel, newChannel: DMChannel | GuildChannel]; channelUpdate: [
oldChannel: DMChannel | NonThreadGuildBasedChannel,
newChannel: DMChannel | NonThreadGuildBasedChannel,
];
warn: [message: string]; warn: [message: string];
emojiCreate: [emoji: GuildEmoji]; emojiCreate: [emoji: GuildEmoji];
emojiDelete: [emoji: GuildEmoji]; emojiDelete: [emoji: GuildEmoji];
@@ -4000,7 +3987,7 @@ export interface CommandInteractionOption<Cached extends CacheType = CacheType>
options?: CommandInteractionOption[]; options?: CommandInteractionOption[];
user?: User; user?: User;
member?: CacheTypeReducer<Cached, GuildMember, APIInteractionDataResolvedGuildMember>; member?: CacheTypeReducer<Cached, GuildMember, APIInteractionDataResolvedGuildMember>;
channel?: CacheTypeReducer<Cached, GuildChannel | ThreadChannel, APIInteractionDataResolvedChannel>; channel?: CacheTypeReducer<Cached, GuildBasedChannel, APIInteractionDataResolvedChannel>;
role?: CacheTypeReducer<Cached, Role, APIRole>; role?: CacheTypeReducer<Cached, Role, APIRole>;
message?: GuildCacheMessage<Cached>; message?: GuildCacheMessage<Cached>;
} }
@@ -4009,7 +3996,7 @@ export interface CommandInteractionResolvedData<Cached extends CacheType = Cache
users?: Collection<Snowflake, User>; users?: Collection<Snowflake, User>;
members?: Collection<Snowflake, CacheTypeReducer<Cached, GuildMember, APIInteractionDataResolvedGuildMember>>; members?: Collection<Snowflake, CacheTypeReducer<Cached, GuildMember, APIInteractionDataResolvedGuildMember>>;
roles?: Collection<Snowflake, CacheTypeReducer<Cached, Role, APIRole>>; roles?: Collection<Snowflake, CacheTypeReducer<Cached, Role, APIRole>>;
channels?: Collection<Snowflake, CacheTypeReducer<Cached, Channel, APIInteractionDataResolvedChannel>>; channels?: Collection<Snowflake, CacheTypeReducer<Cached, AnyChannel, APIInteractionDataResolvedChannel>>;
messages?: Collection<Snowflake, CacheTypeReducer<Cached, Message, APIMessage>>; messages?: Collection<Snowflake, CacheTypeReducer<Cached, Message, APIMessage>>;
} }
@@ -4425,7 +4412,7 @@ export type GuildAuditLogsActionType = GuildAuditLogsTypes[keyof GuildAuditLogsT
export interface GuildAuditLogsEntryExtraField { export interface GuildAuditLogsEntryExtraField {
MEMBER_PRUNE: { removed: number; days: number }; MEMBER_PRUNE: { removed: number; days: number };
MEMBER_MOVE: { channel: VoiceChannel | StageChannel | { id: Snowflake }; count: number }; MEMBER_MOVE: { channel: VoiceBasedChannel | { id: Snowflake }; count: number };
MESSAGE_DELETE: { channel: GuildTextBasedChannel | { id: Snowflake }; count: number }; MESSAGE_DELETE: { channel: GuildTextBasedChannel | { id: Snowflake }; count: number };
MESSAGE_BULK_DELETE: { channel: GuildTextBasedChannel | { id: Snowflake }; count: number }; MESSAGE_BULK_DELETE: { channel: GuildTextBasedChannel | { id: Snowflake }; count: number };
MESSAGE_PIN: { channel: GuildTextBasedChannel | { id: Snowflake }; messageId: Snowflake }; MESSAGE_PIN: { channel: GuildTextBasedChannel | { id: Snowflake }; messageId: Snowflake };
@@ -4458,7 +4445,7 @@ export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLo
INVITE: Invite; INVITE: Invite;
MESSAGE: TActionType extends 'MESSAGE_BULK_DELETE' ? Guild | { id: Snowflake } : User; MESSAGE: TActionType extends 'MESSAGE_BULK_DELETE' ? Guild | { id: Snowflake } : User;
INTEGRATION: Integration; INTEGRATION: Integration;
CHANNEL: GuildChannel | { id: Snowflake; [x: string]: unknown }; CHANNEL: NonThreadGuildBasedChannel | { id: Snowflake; [x: string]: unknown };
THREAD: ThreadChannel | { id: Snowflake; [x: string]: unknown }; THREAD: ThreadChannel | { id: Snowflake; [x: string]: unknown };
STAGE_INSTANCE: StageInstance; STAGE_INSTANCE: StageInstance;
STICKER: Sticker; STICKER: Sticker;
@@ -4486,7 +4473,7 @@ export interface GuildChannelOverwriteOptions {
type?: number; type?: number;
} }
export type GuildChannelResolvable = Snowflake | GuildChannel | ThreadChannel; export type GuildChannelResolvable = Snowflake | GuildBasedChannel;
export interface GuildChannelCreateOptions extends Omit<CategoryCreateChannelOptions, 'type'> { export interface GuildChannelCreateOptions extends Omit<CategoryCreateChannelOptions, 'type'> {
parent?: CategoryChannelResolvable; parent?: CategoryChannelResolvable;
@@ -4520,7 +4507,7 @@ export interface GuildCreateOptions {
export interface GuildWidgetSettings { export interface GuildWidgetSettings {
enabled: boolean; enabled: boolean;
channel: GuildChannel | null; channel: NonThreadGuildBasedChannel | null;
} }
export interface GuildEditData { export interface GuildEditData {
@@ -4600,7 +4587,7 @@ export interface GuildMemberEditData {
export type GuildMemberResolvable = GuildMember | UserResolvable; export type GuildMemberResolvable = GuildMember | UserResolvable;
export type GuildResolvable = Guild | GuildChannel | GuildMember | GuildEmoji | Invite | Role | Snowflake; export type GuildResolvable = Guild | NonThreadGuildBasedChannel | GuildMember | GuildEmoji | Invite | Role | Snowflake;
export interface GuildPruneMembersOptions { export interface GuildPruneMembersOptions {
count?: boolean; count?: boolean;
@@ -4629,7 +4616,7 @@ export interface GuildListMembersOptions {
export type GuildTemplateResolvable = string; export type GuildTemplateResolvable = string;
export type GuildVoiceChannelResolvable = VoiceChannel | StageChannel | Snowflake; export type GuildVoiceChannelResolvable = VoiceBasedChannel | Snowflake;
export type HexColorString = `#${string}`; export type HexColorString = `#${string}`;
@@ -4669,7 +4656,7 @@ export type IntegrationType = 'twitch' | 'youtube' | 'discord';
export interface InteractionCollectorOptions<T extends Interaction, Cached extends CacheType = CacheType> export interface InteractionCollectorOptions<T extends Interaction, Cached extends CacheType = CacheType>
extends CollectorOptions<[T]> { extends CollectorOptions<[T]> {
channel?: TextBasedChannels; channel?: TextBasedChannel;
componentType?: MessageComponentType | MessageComponentTypes; componentType?: MessageComponentType | MessageComponentTypes;
guild?: Guild; guild?: Guild;
interactionType?: InteractionType | InteractionTypes; interactionType?: InteractionType | InteractionTypes;
@@ -5000,7 +4987,7 @@ export interface MessageSelectOptionData {
export type MessageTarget = export type MessageTarget =
| Interaction | Interaction
| InteractionWebhook | InteractionWebhook
| TextBasedChannels | TextBasedChannel
| User | User
| GuildMember | GuildMember
| Webhook | Webhook
@@ -5366,9 +5353,28 @@ export interface LimitedCollectionOptions<K, V> {
sweepInterval?: number; sweepInterval?: number;
} }
export type TextBasedChannels = PartialDMChannel | DMChannel | TextChannel | NewsChannel | ThreadChannel; export type AnyChannel =
| CategoryChannel
| DMChannel
| PartialDMChannel
| NewsChannel
| StageChannel
| StoreChannel
| TextChannel
| ThreadChannel
| VoiceChannel;
export type TextBasedChannelTypes = TextBasedChannels['type']; export type TextBasedChannel = Extract<AnyChannel, { messages: MessageManager }>;
export type TextBasedChannelTypes = TextBasedChannel['type'];
export type VoiceBasedChannel = Extract<AnyChannel, { bitrate: number }>;
export type GuildBasedChannel = Extract<AnyChannel, { guild: Guild }>;
export type NonThreadGuildBasedChannel = Exclude<GuildBasedChannel, ThreadChannel>;
export type GuildTextBasedChannel = Extract<GuildBasedChannel, TextBasedChannel>;
export type TextChannelResolvable = Snowflake | TextChannel; export type TextChannelResolvable = Snowflake | TextChannel;
@@ -5425,7 +5431,7 @@ export interface Vanity {
export type VerificationLevel = keyof typeof VerificationLevels; export type VerificationLevel = keyof typeof VerificationLevels;
export type VoiceBasedChannelTypes = 'GUILD_VOICE' | 'GUILD_STAGE_VOICE'; export type VoiceBasedChannelTypes = VoiceBasedChannel['type'];
export type VoiceChannelResolvable = Snowflake | VoiceChannel; export type VoiceChannelResolvable = Snowflake | VoiceChannel;

View File

@@ -37,13 +37,11 @@ import {
DMChannel, DMChannel,
Guild, Guild,
GuildApplicationCommandManager, GuildApplicationCommandManager,
GuildChannel,
GuildChannelManager, GuildChannelManager,
GuildEmoji, GuildEmoji,
GuildEmojiManager, GuildEmojiManager,
GuildMember, GuildMember,
GuildResolvable, GuildResolvable,
GuildTextBasedChannel,
Intents, Intents,
Interaction, Interaction,
InteractionCollector, InteractionCollector,
@@ -72,7 +70,12 @@ import {
StageChannel, StageChannel,
StoreChannel, StoreChannel,
TextBasedChannelFields, TextBasedChannelFields,
TextBasedChannels, TextBasedChannel,
TextBasedChannelTypes,
VoiceBasedChannel,
GuildBasedChannel,
NonThreadGuildBasedChannel,
GuildTextBasedChannel,
TextChannel, TextChannel,
ThreadChannel, ThreadChannel,
ThreadMember, ThreadMember,
@@ -89,6 +92,7 @@ import {
Emoji, Emoji,
MessageActionRowComponent, MessageActionRowComponent,
MessageSelectMenu, MessageSelectMenu,
PartialDMChannel,
} from '.'; } from '.';
import type { ApplicationCommandOptionTypes } from './enums'; import type { ApplicationCommandOptionTypes } from './enums';
import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd'; import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd';
@@ -542,7 +546,7 @@ client.on('messageCreate', async message => {
expectType<GuildMember | null>(message.member); expectType<GuildMember | null>(message.member);
} }
expectType<TextBasedChannels>(message.channel); expectType<TextBasedChannel>(message.channel);
expectNotType<GuildTextBasedChannel>(message.channel); expectNotType<GuildTextBasedChannel>(message.channel);
// @ts-expect-error // @ts-expect-error
@@ -890,7 +894,7 @@ declare const typing: Typing;
expectType<PartialUser>(typing.user); expectType<PartialUser>(typing.user);
if (typing.user.partial) expectType<null>(typing.user.username); if (typing.user.partial) expectType<null>(typing.user.username);
expectType<TextBasedChannels>(typing.channel); expectType<TextBasedChannel>(typing.channel);
if (typing.channel.partial) expectType<undefined>(typing.channel.lastMessageId); if (typing.channel.partial) expectType<undefined>(typing.channel.lastMessageId);
expectType<GuildMember | null>(typing.member); expectType<GuildMember | null>(typing.member);
@@ -1076,7 +1080,7 @@ client.on('interactionCreate', async interaction => {
expectAssignable<CommandInteraction>(interaction); expectAssignable<CommandInteraction>(interaction);
expectType<Promise<Message<true>>>(interaction.reply({ fetchReply: true })); expectType<Promise<Message<true>>>(interaction.reply({ fetchReply: true }));
expectType<GuildChannel | ThreadChannel>(interaction.options.getChannel('test', true)); expectType<GuildBasedChannel>(interaction.options.getChannel('test', true));
expectType<Role>(interaction.options.getRole('test', true)); expectType<Role>(interaction.options.getRole('test', true));
} else { } else {
// @ts-expect-error // @ts-expect-error
@@ -1086,9 +1090,7 @@ client.on('interactionCreate', async interaction => {
expectType<APIInteractionDataResolvedGuildMember | GuildMember | null>(interaction.options.getMember('test')); expectType<APIInteractionDataResolvedGuildMember | GuildMember | null>(interaction.options.getMember('test'));
expectType<APIInteractionDataResolvedGuildMember | GuildMember>(interaction.options.getMember('test', true)); expectType<APIInteractionDataResolvedGuildMember | GuildMember>(interaction.options.getMember('test', true));
expectType<GuildChannel | ThreadChannel | APIInteractionDataResolvedChannel>( expectType<GuildBasedChannel | APIInteractionDataResolvedChannel>(interaction.options.getChannel('test', true));
interaction.options.getChannel('test', true),
);
expectType<APIRole | Role>(interaction.options.getRole('test', true)); expectType<APIRole | Role>(interaction.options.getRole('test', true));
} }
@@ -1229,3 +1231,23 @@ expectType<Promise<User | undefined>>(
// @ts-expect-error Invalid audit log ID // @ts-expect-error Invalid audit log ID
guild.fetchAuditLogs({ type: 2000 }).then(al => al.entries.first()?.target), guild.fetchAuditLogs({ type: 2000 }).then(al => al.entries.first()?.target),
); );
declare const TextBasedChannel: TextBasedChannel;
declare const TextBasedChannelTypes: TextBasedChannelTypes;
declare const VoiceBasedChannel: VoiceBasedChannel;
declare const GuildBasedChannel: GuildBasedChannel;
declare const NonThreadGuildBasedChannel: NonThreadGuildBasedChannel;
declare const GuildTextBasedChannel: GuildTextBasedChannel;
expectType<DMChannel | PartialDMChannel | NewsChannel | TextChannel | ThreadChannel>(TextBasedChannel);
expectType<'DM' | 'GUILD_NEWS' | 'GUILD_TEXT' | 'GUILD_PUBLIC_THREAD' | 'GUILD_PRIVATE_THREAD' | 'GUILD_NEWS_THREAD'>(
TextBasedChannelTypes,
);
expectType<StageChannel | VoiceChannel>(VoiceBasedChannel);
expectType<CategoryChannel | NewsChannel | StageChannel | StoreChannel | TextChannel | ThreadChannel | VoiceChannel>(
GuildBasedChannel,
);
expectType<CategoryChannel | NewsChannel | StageChannel | StoreChannel | TextChannel | VoiceChannel>(
NonThreadGuildBasedChannel,
);
expectType<NewsChannel | TextChannel | ThreadChannel>(GuildTextBasedChannel);