types: use api-types for stricter typings (#6230)

* types: use api-types for stricter typings

* fix: fixes from pr comments

Co-Authored-By: Vlad Frangu <kingdgrizzle@gmail.com>
Co-Authored-By: Antonio Román <kyradiscord@gmail.com>

* types: bigint not BigInt

Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
ckohen
2021-07-31 14:48:11 -07:00
committed by GitHub
parent 24931d713b
commit 00c2bf81cd
3 changed files with 392 additions and 96 deletions

279
typings/index.d.ts vendored
View File

@@ -17,17 +17,23 @@ import { Collection } from '@discordjs/collection';
import { ChildProcess } from 'child_process';
import {
APIActionRowComponent,
APIApplicationCommand,
APIApplicationCommandInteractionData,
APIApplicationCommandInteractionDataOption,
APIApplicationCommandPermission,
APIAuditLogChange,
APIEmoji,
APIInteractionDataResolvedChannel,
APIInteractionDataResolvedGuildMember,
APIInteractionGuildMember,
APIMessage,
APIMessageComponent,
APIOverwrite,
APIPartialChannel,
APIPartialEmoji,
APIPartialGuild,
APIRole,
APISticker,
APIStickerItem,
APIStickerPack,
APITemplateSerializedSourceGuild,
APIUser,
GatewayVoiceServerUpdateDispatchData,
GatewayVoiceStateUpdateDispatchData,
@@ -35,6 +41,7 @@ import {
} from 'discord-api-types/v9';
import { EventEmitter } from 'events';
import { Stream } from 'stream';
import { MessagePort, Worker } from 'worker_threads';
import * as WebSocket from 'ws';
import {
ActivityTypes,
@@ -59,11 +66,69 @@ import {
VerificationLevels,
WebhookTypes,
} from './enums';
import {
RawActivityData,
RawAnonymousGuildData,
RawApplicationCommandData,
RawApplicationData,
RawBaseGuildData,
RawChannelData,
RawClientApplicationData,
RawCommandInteractionData,
RawDMChannelData,
RawEmojiData,
RawGuildAuditLogData,
RawGuildAuditLogEntryData,
RawGuildBanData,
RawGuildChannelData,
RawGuildData,
RawGuildEmojiData,
RawGuildMemberData,
RawGuildPreviewData,
RawGuildTemplateData,
RawIntegrationApplicationData,
RawIntegrationData,
RawInteractionData,
RawInviteData,
RawInviteGuildData,
RawInviteStageInstance,
RawMessageAttachementData,
RawMessageButtonInteractionData,
RawMessageComponentInteractionData,
RawMessageData,
RawMessagePayloadData,
RawMessageReactionData,
RawMessageSelectMenuInteractionData,
RawOAuth2GuildData,
RawPartialGroupDMChannelData,
RawPartialMessageData,
RawPermissionOverwriteData,
RawPresenceData,
RawReactionEmojiData,
RawRichPresenceAssets,
RawRoleData,
RawStageInstanceData,
RawStickerData,
RawStickerPackData,
RawTeamData,
RawTeamMemberData,
RawThreadChannelData,
RawThreadMemberData,
RawTypingData,
RawUserData,
RawVoiceRegionData,
RawVoiceStateData,
RawWebhookData,
RawWelcomeChannelData,
RawWelcomeScreenData,
RawWidgetData,
RawWidgetMemberData,
} from './rawDataTypes';
//#region Classes
export class Activity {
public constructor(presence: Presence, data?: unknown);
public constructor(presence: Presence, data?: RawActivityData);
public applicationId: Snowflake | null;
public assets: RichPresenceAssets | null;
public buttons: string[];
@@ -97,7 +162,7 @@ export class ActivityFlags extends BitField<ActivityFlagsString> {
}
export abstract class AnonymousGuild extends BaseGuild {
public constructor(client: Client, data: unknown, immediatePatch?: boolean);
public constructor(client: Client, data: RawAnonymousGuildData, immediatePatch?: boolean);
public banner: string | null;
public description: string | null;
public nsfwLevel: NSFWLevel;
@@ -109,7 +174,7 @@ export abstract class AnonymousGuild extends BaseGuild {
}
export abstract class Application extends Base {
public constructor(client: Client, data: unknown);
public constructor(client: Client, data: RawApplicationData);
public readonly createdAt: Date;
public readonly createdTimestamp: number;
public description: string | null;
@@ -124,7 +189,7 @@ export abstract class Application extends Base {
}
export class ApplicationCommand<PermissionsFetchType = {}> extends Base {
public constructor(client: Client, data: unknown, guild?: Guild, guildId?: Snowflake);
public constructor(client: Client, data: RawApplicationCommandData, guild?: Guild, guildId?: Snowflake);
public applicationId: Snowflake;
public readonly createdAt: Date;
public readonly createdTimestamp: number;
@@ -175,7 +240,7 @@ export class BaseClient extends EventEmitter {
}
export abstract class BaseGuild extends Base {
public constructor(client: Client, data: unknown);
public constructor(client: Client, data: RawBaseGuildData);
public readonly createdAt: Date;
public readonly createdTimestamp: number;
public features: GuildFeatures[];
@@ -191,7 +256,7 @@ export abstract class BaseGuild extends Base {
}
export class BaseGuildEmoji extends Emoji {
public constructor(client: Client, data: unknown, guild: Guild | GuildPreview);
public constructor(client: Client, data: RawGuildEmojiData, guild: Guild | GuildPreview);
public available: boolean | null;
public readonly createdAt: Date;
public readonly createdTimestamp: number;
@@ -202,7 +267,7 @@ export class BaseGuildEmoji extends Emoji {
}
export class BaseGuildVoiceChannel extends GuildChannel {
public constructor(guild: Guild, data?: unknown);
public constructor(guild: Guild, data?: RawGuildChannelData);
public readonly members: Collection<Snowflake, GuildMember>;
public readonly full: boolean;
public readonly joinable: boolean;
@@ -238,11 +303,12 @@ export class BitField<S extends string, N extends number | bigint = number> {
public toJSON(): N extends number ? number : string;
public valueOf(): N;
public [Symbol.iterator](): IterableIterator<S>;
public static FLAGS: unknown;
public static FLAGS: Record<string, number | bigint>;
public static resolve(bit?: BitFieldResolvable<string, number | bigint>): number | bigint;
}
export class ButtonInteraction extends MessageComponentInteraction {
public constructor(client: Client, data: RawMessageButtonInteractionData);
public componentType: 'BUTTON';
}
@@ -254,7 +320,7 @@ export class CategoryChannel extends GuildChannel {
export type CategoryChannelResolvable = Snowflake | CategoryChannel;
export class Channel extends Base {
public constructor(client: Client, data?: unknown, immediatePatch?: boolean);
public constructor(client: Client, data?: RawChannelData, immediatePatch?: boolean);
public readonly createdAt: Date;
public readonly createdTimestamp: number;
public deleted: boolean;
@@ -331,6 +397,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
}
export class ClientApplication extends Application {
public constructor(client: Client, data: RawClientApplicationData);
public botPublic: boolean | null;
public botRequireCodeGrant: boolean | null;
public commands: ApplicationCommandManager;
@@ -402,6 +469,7 @@ export abstract class Collector<K, V, F extends unknown[] = []> extends EventEmi
}
export class CommandInteraction extends Interaction {
public constructor(client: Client, data: RawCommandInteractionData);
public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null;
public readonly channel: TextChannel | DMChannel | NewsChannel | PartialDMChannel | ThreadChannel | null;
public channelId: Snowflake;
@@ -420,7 +488,10 @@ export class CommandInteraction extends Interaction {
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<Message | APIMessage>;
public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<Message | APIMessage>;
public reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>;
private transformOption(option: unknown, resolved: unknown): CommandInteractionOption;
private transformOption(
option: APIApplicationCommandInteractionDataOption,
resolved: APIApplicationCommandInteractionData['resolved'],
): CommandInteractionOption;
}
export class CommandInteractionOptionResolver {
@@ -499,7 +570,7 @@ export class DiscordAPIError extends Error {
}
export class DMChannel extends TextBasedChannel(Channel, ['bulkDelete']) {
public constructor(client: Client, data?: unknown);
public constructor(client: Client, data?: RawDMChannelData);
public messages: MessageManager;
public recipient: User;
public type: 'DM';
@@ -507,7 +578,7 @@ export class DMChannel extends TextBasedChannel(Channel, ['bulkDelete']) {
}
export class Emoji extends Base {
public constructor(client: Client, emoji: unknown);
public constructor(client: Client, emoji: RawEmojiData);
public animated: boolean | null;
public readonly createdAt: Date | null;
public readonly createdTimestamp: number | null;
@@ -521,7 +592,7 @@ export class Emoji extends Base {
}
export class Guild extends AnonymousGuild {
public constructor(client: Client, data: unknown);
public constructor(client: Client, data: RawGuildData);
private _sortedRoles(): Collection<Snowflake, Role>;
private _sortedChannels(channel: Channel): Collection<Snowflake, GuildChannel>;
@@ -619,7 +690,7 @@ export class Guild extends AnonymousGuild {
}
export class GuildAuditLogs {
public constructor(guild: Guild, data: unknown);
public constructor(guild: Guild, data: RawGuildAuditLogData);
private webhooks: Collection<Snowflake, Webhook>;
private integrations: Collection<Snowflake, Integration>;
@@ -635,7 +706,7 @@ export class GuildAuditLogs {
}
export class GuildAuditLogsEntry {
public constructor(logs: GuildAuditLogs, guild: Guild, data: unknown);
public constructor(logs: GuildAuditLogs, guild: Guild, data: RawGuildAuditLogEntryData);
public action: GuildAuditLogsAction;
public actionType: GuildAuditLogsActionType;
public changes: AuditLogChange[] | null;
@@ -665,7 +736,7 @@ export class GuildAuditLogsEntry {
}
export class GuildBan extends Base {
public constructor(client: Client, data: unknown, guild: Guild);
public constructor(client: Client, data: RawGuildBanData, guild: Guild);
public guild: Guild;
public user: User;
public readonly partial: boolean;
@@ -674,7 +745,7 @@ export class GuildBan extends Base {
}
export class GuildChannel extends Channel {
public constructor(guild: Guild, data?: unknown, client?: Client);
public constructor(guild: Guild, data?: RawGuildChannelData, client?: Client);
private memberPermissions(member: GuildMember): Readonly<Permissions>;
private rolePermissions(role: Role): Readonly<Permissions>;
@@ -709,7 +780,7 @@ export class GuildChannel extends Channel {
}
export class GuildEmoji extends BaseGuildEmoji {
public constructor(client: Client, data: unknown, guild: Guild);
public constructor(client: Client, data: RawGuildEmojiData, guild: Guild);
private _roles: Snowflake[];
public readonly deletable: boolean;
@@ -725,7 +796,7 @@ export class GuildEmoji extends BaseGuildEmoji {
}
export class GuildMember extends PartialTextBasedChannel(Base) {
public constructor(client: Client, data: unknown, guild: Guild);
public constructor(client: Client, data: RawGuildMemberData, guild: Guild);
public readonly bannable: boolean;
public deleted: boolean;
public readonly displayColor: number;
@@ -761,7 +832,7 @@ export class GuildMember extends PartialTextBasedChannel(Base) {
}
export class GuildPreview extends Base {
public constructor(client: Client, data: unknown);
public constructor(client: Client, data: RawGuildPreviewData);
public approximateMemberCount: number;
public approximatePresenceCount: number;
public readonly createdAt: Date;
@@ -783,7 +854,7 @@ export class GuildPreview extends Base {
}
export class GuildTemplate extends Base {
public constructor(client: Client, data: unknown);
public constructor(client: Client, data: RawGuildTemplateData);
public readonly createdTimestamp: number;
public readonly updatedTimestamp: number;
public readonly url: string;
@@ -797,7 +868,7 @@ export class GuildTemplate extends Base {
public updatedAt: Date;
public guild: Guild | null;
public guildId: Snowflake;
public serializedGuild: unknown;
public serializedGuild: APITemplateSerializedSourceGuild;
public unSynced: boolean | null;
public createGuild(name: string, icon?: BufferResolvable | Base64Resolvable): Promise<Guild>;
public delete(): Promise<GuildTemplate>;
@@ -807,7 +878,7 @@ export class GuildTemplate extends Base {
}
export class GuildPreviewEmoji extends BaseGuildEmoji {
public constructor(client: Client, data: unknown, guild: GuildPreview);
public constructor(client: Client, data: RawGuildEmojiData, guild: GuildPreview);
public guild: GuildPreview;
public roles: Snowflake[];
}
@@ -829,7 +900,7 @@ export class RateLimitError extends Error {
}
export class Integration extends Base {
public constructor(client: Client, data: unknown, guild: Guild);
public constructor(client: Client, data: RawIntegrationData, guild: Guild);
public account: IntegrationAccount;
public application: IntegrationApplication | null;
public enabled: boolean;
@@ -848,6 +919,7 @@ export class Integration extends Base {
}
export class IntegrationApplication extends Application {
public constructor(client: Client, data: RawIntegrationApplicationData);
public bot: User | null;
public termsOfServiceURL: string | null;
public privacyPolicyURL: string | null;
@@ -864,7 +936,7 @@ export class Intents extends BitField<IntentsString> {
}
export class Interaction extends Base {
public constructor(client: Client, data: unknown);
public constructor(client: Client, data: RawInteractionData);
public applicationId: Snowflake;
public readonly channel: Channel | PartialDMChannel | null;
public channelId: Snowflake | null;
@@ -920,7 +992,7 @@ export class InteractionWebhook extends PartialWebhookMixin() {
}
export class Invite extends Base {
public constructor(client: Client, data: unknown);
public constructor(client: Client, data: RawInviteData);
public channel: GuildChannel | PartialGroupDMChannel;
public code: string;
public readonly deletable: boolean;
@@ -948,7 +1020,7 @@ export class Invite extends Base {
}
export class InviteStageInstance extends Base {
public constructor(client: Client, data: unknown, channelId: Snowflake, guildId: Snowflake);
public constructor(client: Client, data: RawInviteStageInstance, channelId: Snowflake, guildId: Snowflake);
public channelId: Snowflake;
public guildId: Snowflake;
public members: Collection<Snowflake, GuildMember>;
@@ -960,7 +1032,7 @@ export class InviteStageInstance extends Base {
}
export class InviteGuild extends AnonymousGuild {
public constructor(client: Client, data: unknown);
public constructor(client: Client, data: RawInviteGuildData);
public welcomeScreen: WelcomeScreen | null;
}
@@ -975,9 +1047,15 @@ export class LimitedCollection<K, V> extends Collection<K, V> {
}
export class Message extends Base {
public constructor(client: Client, data: unknown, channel: TextChannel | DMChannel | NewsChannel | ThreadChannel);
private _patch(data: unknown, partial?: boolean): Message;
private _update(data: unknown, partial?: boolean): Message;
public constructor(
client: Client,
data: RawMessageData,
channel: TextChannel | DMChannel | NewsChannel | ThreadChannel,
);
private _patch(data: RawPartialMessageData, partial: true): Message;
private _patch(data: RawMessageData, partial?: boolean): Message;
private _update(data: RawPartialMessageData, partial: true): Message;
private _update(data: RawMessageData, partial?: boolean): Message;
public activity: MessageActivity | null;
public applicationId: Snowflake | null;
@@ -1059,7 +1137,7 @@ export class MessageActionRow extends BaseMessageComponent {
}
export class MessageAttachment {
public constructor(attachment: BufferResolvable | Stream, name?: string, data?: unknown);
public constructor(attachment: BufferResolvable | Stream, name?: string, data?: RawMessageAttachementData);
public attachment: BufferResolvable | Stream;
public contentType: string | null;
@@ -1110,6 +1188,7 @@ export class MessageCollector extends Collector<Snowflake, Message> {
}
export class MessageComponentInteraction extends Interaction {
public constructor(client: Client, data: RawMessageComponentInteractionData);
public readonly channel: TextChannel | DMChannel | NewsChannel | PartialDMChannel | ThreadChannel | null;
public readonly component: MessageActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent> | null;
public componentType: MessageComponentType;
@@ -1210,7 +1289,7 @@ export class MessageMentions {
export class MessagePayload {
public constructor(target: MessageTarget, options: MessageOptions | WebhookMessageOptions);
public data: unknown | null;
public data: RawMessagePayloadData | null;
public readonly isUser: boolean;
public readonly isWebhook: boolean;
public readonly isMessage: boolean;
@@ -1233,7 +1312,7 @@ export class MessagePayload {
}
export class MessageReaction {
public constructor(client: Client, data: unknown, message: Message);
public constructor(client: Client, data: RawMessageReactionData, message: Message);
private _emoji: GuildEmoji | ReactionEmoji;
public readonly client: Client;
@@ -1272,7 +1351,7 @@ export class MessageSelectMenu extends BaseMessageComponent {
}
export class NewsChannel extends TextBasedChannel(GuildChannel) {
public constructor(guild: Guild, data?: unknown);
public constructor(guild: Guild, data?: RawGuildChannelData);
public defaultAutoArchiveDuration?: ThreadAutoArchiveDuration;
public messages: MessageManager;
public nsfw: boolean;
@@ -1291,19 +1370,20 @@ export class NewsChannel extends TextBasedChannel(GuildChannel) {
}
export class OAuth2Guild extends BaseGuild {
public constructor(client: Client, data: RawOAuth2GuildData);
public owner: boolean;
public permissions: Readonly<Permissions>;
}
export class PartialGroupDMChannel extends Channel {
public constructor(client: Client, data: unknown);
public constructor(client: Client, data: RawPartialGroupDMChannelData);
public name: string;
public icon: string | null;
public iconURL(options?: StaticImageURLOptions): string | null;
}
export class PermissionOverwrites extends Base {
public constructor(client: Client, data: object, channel: GuildChannel);
public constructor(client: Client, data: RawPermissionOverwriteData, channel: GuildChannel);
public allow: Readonly<Permissions>;
public readonly channel: GuildChannel;
public deny: Readonly<Permissions>;
@@ -1334,7 +1414,7 @@ export class Permissions extends BitField<PermissionString, bigint> {
}
export class Presence extends Base {
public constructor(client: Client, data?: unknown);
public constructor(client: Client, data?: RawPresenceData);
public activities: Activity[];
public clientStatus: ClientPresenceStatusData | null;
public guild: Guild | null;
@@ -1376,13 +1456,13 @@ export class ReactionCollector extends Collector<Snowflake | string, MessageReac
}
export class ReactionEmoji extends Emoji {
public constructor(reaction: MessageReaction, emoji: unknown);
public constructor(reaction: MessageReaction, emoji: RawReactionEmojiData);
public reaction: MessageReaction;
public toJSON(): unknown;
}
export class RichPresenceAssets {
public constructor(activity: Activity, assets: unknown);
public constructor(activity: Activity, assets: RawRichPresenceAssets);
public largeImage: Snowflake | null;
public largeText: string | null;
public smallImage: Snowflake | null;
@@ -1392,7 +1472,7 @@ export class RichPresenceAssets {
}
export class Role extends Base {
public constructor(client: Client, data: unknown, guild: Guild);
public constructor(client: Client, data: RawRoleData, guild: Guild);
public color: number;
public readonly createdAt: Date;
public readonly createdTimestamp: number;
@@ -1428,6 +1508,7 @@ export class Role extends Base {
}
export class SelectMenuInteraction extends MessageComponentInteraction {
public constructor(client: Client, data: RawMessageSelectMenuInteractionData);
public componentType: 'SELECT_MENU';
public values: string[];
}
@@ -1447,7 +1528,7 @@ export class Shard extends EventEmitter {
public manager: ShardingManager;
public process: ChildProcess | null;
public ready: boolean;
public worker: unknown | null;
public worker: Worker | null;
public eval(script: string): Promise<unknown>;
public eval<T>(fn: (client: Client) => T): Promise<T[]>;
public fetchClientValue(prop: string): Promise<unknown>;
@@ -1478,7 +1559,7 @@ export class ShardClientUtil {
public readonly count: number;
public readonly ids: number[];
public mode: ShardingManagerMode;
public parentPort: unknown | null;
public parentPort: MessagePort | null;
public broadcastEval<T>(fn: (client: Client) => Awaited<T>): Promise<Serialized<T>[]>;
public broadcastEval<T>(fn: (client: Client) => Awaited<T>, options: { shard: number }): Promise<Serialized<T>>;
public broadcastEval<T, P>(
@@ -1552,7 +1633,7 @@ export class StageChannel extends BaseGuildVoiceChannel {
}
export class StageInstance extends Base {
public constructor(client: Client, data: unknown, channel: StageChannel);
public constructor(client: Client, data: RawStageInstanceData, channel: StageChannel);
public id: Snowflake;
public deleted: boolean;
public guildId: Snowflake;
@@ -1570,7 +1651,7 @@ export class StageInstance extends Base {
}
export class Sticker extends Base {
public constructor(client: Client, data: APISticker | APIStickerItem);
public constructor(client: Client, data: RawStickerData);
public readonly createdTimestamp: number;
public readonly createdAt: Date;
public available: boolean | null;
@@ -1596,7 +1677,7 @@ export class Sticker extends Base {
}
export class StickerPack extends Base {
public constructor(client: Client, data: APIStickerPack);
public constructor(client: Client, data: RawStickerPackData);
public readonly createdTimestamp: number;
public readonly createdAt: Date;
public bannerId: Snowflake;
@@ -1611,7 +1692,7 @@ export class StickerPack extends Base {
}
export class StoreChannel extends GuildChannel {
public constructor(guild: Guild, data?: unknown, client?: Client);
public constructor(guild: Guild, data?: RawGuildChannelData, client?: Client);
public nsfw: boolean;
public type: 'GUILD_STORE';
}
@@ -1622,7 +1703,7 @@ export class SystemChannelFlags extends BitField<SystemChannelFlagsString> {
}
export class Team extends Base {
public constructor(client: Client, data: unknown);
public constructor(client: Client, data: RawTeamData);
public id: Snowflake;
public name: string;
public icon: string | null;
@@ -1639,7 +1720,7 @@ export class Team extends Base {
}
export class TeamMember extends Base {
public constructor(team: Team, data: unknown);
public constructor(team: Team, data: RawTeamMemberData);
public team: Team;
public readonly id: Snowflake;
public permissions: string[];
@@ -1650,7 +1731,7 @@ export class TeamMember extends Base {
}
export class TextChannel extends TextBasedChannel(GuildChannel) {
public constructor(guild: Guild, data?: unknown, client?: Client);
public constructor(guild: Guild, data?: RawGuildChannelData, client?: Client);
public defaultAutoArchiveDuration?: ThreadAutoArchiveDuration;
public messages: MessageManager;
public nsfw: boolean;
@@ -1670,7 +1751,7 @@ export class TextChannel extends TextBasedChannel(GuildChannel) {
}
export class ThreadChannel extends TextBasedChannel(Channel) {
public constructor(guild: Guild, data?: object, client?: Client, fromInteraction?: boolean);
public constructor(guild: Guild, data?: RawThreadChannelData, client?: Client, fromInteraction?: boolean);
public archived: boolean | null;
public readonly archivedAt: Date | null;
public archiveTimestamp: number | null;
@@ -1713,7 +1794,7 @@ export class ThreadChannel extends TextBasedChannel(Channel) {
}
export class ThreadMember extends Base {
public constructor(thread: ThreadChannel, data?: object);
public constructor(thread: ThreadChannel, data?: RawThreadMemberData);
public flags: ThreadMemberFlags;
public readonly guildMember: GuildMember | null;
public id: Snowflake;
@@ -1734,7 +1815,7 @@ export class Typing extends Base {
public constructor(
channel: TextChannel | PartialDMChannel | NewsChannel | ThreadChannel,
user: PartialUser,
data?: object,
data?: RawTypingData,
);
public channel: TextChannel | PartialDMChannel | NewsChannel | ThreadChannel;
public user: PartialUser;
@@ -1749,7 +1830,7 @@ export class Typing extends Base {
}
export class User extends PartialTextBasedChannel(Base) {
public constructor(client: Client, data: unknown);
public constructor(client: Client, data: RawUserData);
public avatar: string | null;
public bot: boolean;
public readonly createdAt: Date;
@@ -1845,7 +1926,7 @@ export class VoiceChannel extends BaseGuildVoiceChannel {
}
export class VoiceRegion {
public constructor(data: unknown);
public constructor(data: RawVoiceRegionData);
public custom: boolean;
public deprecated: boolean;
public id: string;
@@ -1856,7 +1937,7 @@ export class VoiceRegion {
}
export class VoiceState extends Base {
public constructor(guild: Guild, data: unknown);
public constructor(guild: Guild, data: RawVoiceStateData);
public readonly channel: VoiceChannel | StageChannel | null;
public channelId: Snowflake | null;
public readonly deaf: boolean | null;
@@ -1883,16 +1964,16 @@ export class VoiceState extends Base {
}
export class Webhook extends WebhookMixin() {
public constructor(client: Client, data?: unknown);
public constructor(client: Client, data?: RawWebhookData);
public avatar: string;
public avatarURL(options?: StaticImageURLOptions): string | null;
public channelId: Snowflake;
public client: Client;
public guildId: Snowflake;
public name: string;
public owner: User | unknown | null;
public sourceGuild: Guild | unknown | null;
public sourceChannel: Channel | unknown | null;
public owner: User | APIUser | null;
public sourceGuild: Guild | APIPartialGuild | null;
public sourceChannel: Channel | APIPartialChannel | null;
public token: string | null;
public type: WebhookType;
}
@@ -1992,8 +2073,8 @@ export class WebSocketShard extends EventEmitter {
}
export class Widget extends Base {
public constructor(client: Client, data: object);
private _patch(data: object): void;
public constructor(client: Client, data: RawWidgetData);
private _patch(data: RawWidgetData): void;
public fetch(): Promise<Widget>;
public id: Snowflake;
public instantInvite?: string;
@@ -2003,7 +2084,7 @@ export class Widget extends Base {
}
export class WidgetMember extends Base {
public constructor(client: Client, data: object);
public constructor(client: Client, data: RawWidgetMemberData);
public id: string;
public username: string;
public discriminator: string;
@@ -2020,7 +2101,8 @@ export class WidgetMember extends Base {
}
export class WelcomeChannel extends Base {
private _emoji: unknown;
constructor(guild: Guild, data: RawWelcomeChannelData);
private _emoji: Omit<APIEmoji, 'animated'>;
public channelId: Snowflake;
public guild: Guild | InviteGuild;
public description: string;
@@ -2029,6 +2111,7 @@ export class WelcomeChannel extends Base {
}
export class WelcomeScreen extends Base {
constructor(guild: Guild, data: RawWelcomeScreenData);
public readonly enabled: boolean;
public guild: Guild | InviteGuild;
public description: string | null;
@@ -2164,7 +2247,7 @@ export class ApplicationCommandManager<
PermissionsOptionsExtras = { guild: GuildResolvable },
PermissionsGuildType = null,
> extends CachedManager<Snowflake, ApplicationCommandType, ApplicationCommandResolvable> {
public constructor(client: Client, iterable?: Iterable<unknown>);
public constructor(client: Client, iterable?: Iterable<RawApplicationCommandData>);
public permissions: ApplicationCommandPermissionsManager<
{ command?: ApplicationCommandResolvable } & PermissionsOptionsExtras,
{ command: ApplicationCommandResolvable } & PermissionsOptionsExtras,
@@ -2196,7 +2279,9 @@ export class ApplicationCommandManager<
commands: ApplicationCommandData[],
guildId: Snowflake,
): Promise<Collection<Snowflake, ApplicationCommand>>;
private static transformCommand(command: ApplicationCommandData): unknown;
private static transformCommand(
command: ApplicationCommandData,
): Omit<APIApplicationCommand, 'id' | 'application_id' | 'guild_id'>;
}
export class ApplicationCommandPermissionsManager<
@@ -2239,21 +2324,25 @@ export class ApplicationCommandPermissionsManager<
},
): Promise<Collection<Snowflake, ApplicationCommandPermissions[]>>;
private permissionsPath(guildId: Snowflake, commandId?: Snowflake): unknown;
private static transformPermissions(permissions: ApplicationCommandPermissionData, received?: boolean): unknown;
private static transformPermissions(
permissions: ApplicationCommandPermissionData,
received: true,
): Omit<APIApplicationCommandPermission, 'type'> & { type: keyof ApplicationCommandPermissionTypes };
private static transformPermissions(permissions: ApplicationCommandPermissionData): APIApplicationCommandPermission;
}
export class BaseGuildEmojiManager extends CachedManager<Snowflake, GuildEmoji, EmojiResolvable> {
public constructor(client: Client, iterable?: Iterable<unknown>);
public constructor(client: Client, iterable?: Iterable<RawGuildEmojiData>);
public resolveIdentifier(emoji: EmojiIdentifierResolvable): string | null;
}
export class ChannelManager extends CachedManager<Snowflake, Channel, ChannelResolvable> {
public constructor(client: Client, iterable: Iterable<unknown>);
public constructor(client: Client, iterable: Iterable<RawChannelData>);
public fetch(id: Snowflake, options?: FetchChannelOptions): Promise<Channel | null>;
}
export class GuildApplicationCommandManager extends ApplicationCommandManager<ApplicationCommand, {}, Guild> {
public constructor(guild: Guild, iterable?: Iterable<unknown>);
public constructor(guild: Guild, iterable?: Iterable<RawApplicationCommandData>);
public guild: Guild;
public create(command: ApplicationCommandData): Promise<ApplicationCommand>;
public delete(command: ApplicationCommandResolvable): Promise<ApplicationCommand | null>;
@@ -2268,7 +2357,7 @@ export class GuildChannelManager extends CachedManager<
GuildChannel | ThreadChannel,
GuildChannelResolvable
> {
public constructor(guild: Guild, iterable?: Iterable<unknown>);
public constructor(guild: Guild, iterable?: Iterable<RawGuildChannelData>);
public readonly channelCountWithoutThreads: number;
public guild: Guild;
public create(name: string, options: GuildChannelCreateOptions & { type: 'GUILD_VOICE' }): Promise<VoiceChannel>;
@@ -2301,7 +2390,7 @@ export class GuildChannelManager extends CachedManager<
}
export class GuildEmojiManager extends BaseGuildEmojiManager {
public constructor(guild: Guild, iterable?: Iterable<unknown>);
public constructor(guild: Guild, iterable?: Iterable<RawGuildEmojiData>);
public guild: Guild;
public create(
attachment: BufferResolvable | Base64Resolvable,
@@ -2326,14 +2415,14 @@ export class GuildEmojiRoleManager extends DataManager<Snowflake, Role, RoleReso
}
export class GuildManager extends CachedManager<Snowflake, Guild, GuildResolvable> {
public constructor(client: Client, iterable?: Iterable<unknown>);
public constructor(client: Client, iterable?: Iterable<RawGuildData>);
public create(name: string, options?: GuildCreateOptions): Promise<Guild>;
public fetch(options: Snowflake | FetchGuildOptions): Promise<Guild>;
public fetch(options?: FetchGuildsOptions): Promise<Collection<Snowflake, OAuth2Guild>>;
}
export class GuildMemberManager extends CachedManager<Snowflake, GuildMember, GuildMemberResolvable> {
public constructor(guild: Guild, iterable?: Iterable<unknown>);
public constructor(guild: Guild, iterable?: Iterable<RawGuildMemberData>);
public guild: Guild;
public add(
user: UserResolvable,
@@ -2354,7 +2443,7 @@ export class GuildMemberManager extends CachedManager<Snowflake, GuildMember, Gu
}
export class GuildBanManager extends CachedManager<Snowflake, GuildBan, GuildBanResolvable> {
public constructor(guild: Guild, iterable?: Iterable<unknown>);
public constructor(guild: Guild, iterable?: Iterable<RawGuildBanData>);
public guild: Guild;
public create(user: UserResolvable, options?: BanOptions): Promise<GuildMember | User | Snowflake>;
public fetch(options: UserResolvable | FetchBanOptions): Promise<GuildBan>;
@@ -2363,7 +2452,7 @@ export class GuildBanManager extends CachedManager<Snowflake, GuildBan, GuildBan
}
export class GuildInviteManager extends DataManager<string, Invite, InviteResolvable> {
public constructor(guild: Guild, iterable?: Iterable<unknown>);
public constructor(guild: Guild, iterable?: Iterable<RawInviteData>);
public guild: Guild;
public create(channel: GuildChannelResolvable, options?: CreateInviteOptions): Promise<Invite>;
public fetch(options: InviteResolvable | FetchInviteOptions): Promise<Invite>;
@@ -2372,7 +2461,7 @@ export class GuildInviteManager extends DataManager<string, Invite, InviteResolv
}
export class GuildStickerManager extends CachedManager<Snowflake, Sticker, StickerResolvable> {
public constructor(guild: Guild, iterable?: Iterable<any>);
public constructor(guild: Guild, iterable?: Iterable<RawStickerData>);
public guild: Guild;
public create(
file: BufferResolvable | Stream | FileOptions | MessageAttachment,
@@ -2408,7 +2497,7 @@ export class GuildMemberRoleManager extends DataManager<Snowflake, Role, RoleRes
}
export class MessageManager extends CachedManager<Snowflake, Message, MessageResolvable> {
public constructor(channel: TextChannel | DMChannel | ThreadChannel, iterable?: Iterable<unknown>);
public constructor(channel: TextChannel | DMChannel | ThreadChannel, iterable?: Iterable<RawMessageData>);
public channel: TextBasedChannelFields;
public cache: Collection<Snowflake, Message>;
public crosspost(message: MessageResolvable): Promise<Message>;
@@ -2430,7 +2519,7 @@ export class PermissionOverwriteManager extends CachedManager<
PermissionOverwrites,
PermissionOverwriteResolvable
> {
public constructor(client: Client, iterable?: Iterable<unknown>);
public constructor(client: Client, iterable?: Iterable<RawPermissionOverwriteData>);
public set(
overwrites: readonly OverwriteResolvable[] | Collection<Snowflake, OverwriteResolvable>,
reason?: string,
@@ -2455,24 +2544,24 @@ export class PermissionOverwriteManager extends CachedManager<
}
export class PresenceManager extends CachedManager<Snowflake, Presence, PresenceResolvable> {
public constructor(client: Client, iterable?: Iterable<unknown>);
public constructor(client: Client, iterable?: Iterable<RawPresenceData>);
}
export class ReactionManager extends CachedManager<Snowflake | string, MessageReaction, MessageReactionResolvable> {
public constructor(message: Message, iterable?: Iterable<unknown>);
public constructor(message: Message, iterable?: Iterable<RawMessageReactionData>);
public message: Message;
public removeAll(): Promise<Message>;
}
export class ReactionUserManager extends CachedManager<Snowflake, User, UserResolvable> {
public constructor(reaction: MessageReaction, iterable?: Iterable<unknown>);
public constructor(reaction: MessageReaction, iterable?: Iterable<RawUserData>);
public reaction: MessageReaction;
public fetch(options?: FetchReactionUsersOptions): Promise<Collection<Snowflake, User>>;
public remove(user?: UserResolvable): Promise<MessageReaction>;
}
export class RoleManager extends CachedManager<Snowflake, Role, RoleResolvable> {
public constructor(guild: Guild, iterable?: Iterable<unknown>);
public constructor(guild: Guild, iterable?: Iterable<RawRoleData>);
public readonly everyone: Role;
public readonly highest: Role;
public guild: Guild;
@@ -2485,7 +2574,7 @@ export class RoleManager extends CachedManager<Snowflake, Role, RoleResolvable>
}
export class StageInstanceManager extends CachedManager<Snowflake, StageInstance, StageInstanceResolvable> {
public constructor(guild: Guild, iterable?: Iterable<unknown>);
public constructor(guild: Guild, iterable?: Iterable<RawStageInstanceData>);
public guild: Guild;
public create(channel: StageChannel | Snowflake, options: StageInstanceCreateOptions): Promise<StageInstance>;
public fetch(channel: StageChannel | Snowflake, options?: BaseFetchOptions): Promise<StageInstance>;
@@ -2494,7 +2583,7 @@ export class StageInstanceManager extends CachedManager<Snowflake, StageInstance
}
export class ThreadManager<AllowedThreadType> extends CachedManager<Snowflake, ThreadChannel, ThreadChannelResolvable> {
public constructor(channel: TextChannel | NewsChannel, iterable?: Iterable<unknown>);
public 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>;
@@ -2504,7 +2593,7 @@ export class ThreadManager<AllowedThreadType> extends CachedManager<Snowflake, T
}
export class ThreadMemberManager extends CachedManager<Snowflake, ThreadMember, ThreadMemberResolvable> {
public constructor(thread: ThreadChannel, iterable?: Iterable<unknown>);
public constructor(thread: ThreadChannel, iterable?: Iterable<RawThreadMemberData>);
public thread: ThreadChannel;
public add(member: UserResolvable | '@me', reason?: string): Promise<Snowflake>;
public fetch(cache?: boolean): Promise<Collection<Snowflake, ThreadMember>>;
@@ -2512,12 +2601,12 @@ export class ThreadMemberManager extends CachedManager<Snowflake, ThreadMember,
}
export class UserManager extends CachedManager<Snowflake, User, UserResolvable> {
public constructor(client: Client, iterable?: Iterable<unknown>);
public constructor(client: Client, iterable?: Iterable<RawUserData>);
public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<User>;
}
export class VoiceStateManager extends CachedManager<Snowflake, VoiceState, typeof VoiceState> {
public constructor(guild: Guild, iterable?: Iterable<unknown>);
public constructor(guild: Guild, iterable?: Iterable<RawVoiceStateData>);
public guild: Guild;
}
@@ -2580,7 +2669,7 @@ export interface WebhookFields extends PartialWebhookFields {
readonly createdTimestamp: number;
delete(reason?: string): Promise<void>;
edit(options: WebhookEditData, reason?: string): Promise<Webhook>;
sendSlackMessage(body: object): Promise<boolean>;
sendSlackMessage(body: unknown): Promise<boolean>;
}
//#endregion
@@ -2809,9 +2898,9 @@ export type ApplicationFlagsString =
| 'EMBEDDED';
export interface AuditLogChange {
key: string;
old?: unknown;
new?: unknown;
key: APIAuditLogChange['key'];
old?: APIAuditLogChange['old_value'];
new?: APIAuditLogChange['new_value'];
}
export type Awaited<T> = T | PromiseLike<T>;

207
typings/rawDataTypes.d.ts vendored Normal file
View File

@@ -0,0 +1,207 @@
// These are aggregate types that are used in the typings file but do not exist as actual exported values.
// To prevent them from showing up in an editor, they are imported from here instead of exporting them there directly.
import {
APIApplication,
APIApplicationCommand,
APIApplicationCommandInteraction,
APIAttachment,
APIAuditLog,
APIAuditLogEntry,
APIBan,
APIChannel,
APIEmoji,
APIExtendedInvite,
APIGuild,
APIGuildIntegration,
APIGuildIntegrationApplication,
APIGuildMember,
APIGuildPreview,
APIGuildWelcomeScreen,
APIGuildWelcomeScreenChannel,
APIGuildWidget,
APIGuildWidgetMember,
APIInteractionDataResolvedChannel,
APIInteractionDataResolvedGuildMember,
APIInteractionGuildMember,
APIInvite,
APIInviteStageInstance,
APIMessage,
APIMessageButtonInteractionData,
APIMessageComponentInteraction,
APIMessageSelectMenuInteractionData,
APIOverwrite,
APIPartialChannel,
APIPartialEmoji,
APIPartialGuild,
APIReaction,
APIRole,
APIStageInstance,
APISticker,
APIStickerItem,
APIStickerPack,
APITeam,
APITeamMember,
APITemplate,
APIThreadMember,
APIUnavailableGuild,
APIUser,
APIVoiceRegion,
APIWebhook,
GatewayActivity,
GatewayActivityAssets,
GatewayActivityEmoji,
GatewayGuildBanAddDispatchData,
GatewayGuildMemberAddDispatchData,
GatewayGuildMemberUpdateDispatchData,
GatewayInteractionCreateDispatchData,
GatewayInviteCreateDispatchData,
GatewayInviteDeleteDispatchData,
GatewayMessageReactionAddDispatchData,
GatewayMessageUpdateDispatchData,
GatewayPresenceUpdate,
GatewayReadyDispatchData,
GatewayTypingStartDispatchData,
GatewayVoiceState,
RESTAPIPartialCurrentUserGuild,
RESTGetAPIWebhookWithTokenResult,
RESTPatchAPIChannelMessageJSONBody,
RESTPatchAPICurrentGuildMemberNicknameJSONBody,
RESTPatchAPIInteractionFollowupJSONBody,
RESTPatchAPIInteractionOriginalResponseJSONBody,
RESTPatchAPIWebhookWithTokenJSONBody,
RESTPostAPIChannelMessageJSONBody,
RESTPostAPIInteractionCallbackFormDataBody,
RESTPostAPIInteractionFollowupJSONBody,
RESTPostAPIWebhookWithTokenJSONBody,
Snowflake,
} from 'discord-api-types/v9';
import { GuildChannel, Guild, PermissionOverwrites } from '.';
export type RawActivityData = GatewayActivity;
export type RawApplicationData = RawClientApplicationData | RawIntegrationApplicationData;
export type RawClientApplicationData = GatewayReadyDispatchData['application'] | APIMessage['application'];
export type RawIntegrationApplicationData = APIGuildIntegrationApplication | Partial<APIApplication>;
export type RawApplicationCommandData = APIApplicationCommand;
export type RawChannelData =
| RawGuildChannelData
| RawThreadChannelData
| RawDMChannelData
| RawPartialGroupDMChannelData;
export type RawDMChannelData = APIChannel | APIInteractionDataResolvedChannel;
export type RawGuildChannelData = APIChannel | APIInteractionDataResolvedChannel | Required<APIPartialChannel>;
export type RawPartialGroupDMChannelData = APIChannel | Required<APIPartialChannel>;
export type RawThreadChannelData = APIChannel | APIInteractionDataResolvedChannel;
export type RawEmojiData =
| RawGuildEmojiData
| RawReactionEmojiData
| GatewayActivityEmoji
| Omit<Partial<APIPartialEmoji>, 'animated'>;
export type RawGuildEmojiData = APIEmoji;
export type RawReactionEmojiData = APIEmoji | APIPartialEmoji;
export type RawGuildAuditLogData = APIAuditLog;
export type RawGuildAuditLogEntryData = APIAuditLogEntry;
export type RawGuildBanData = GatewayGuildBanAddDispatchData | APIBan;
export type RawGuildData = APIGuild | APIUnavailableGuild;
export type RawAnonymousGuildData = RawGuildData | RawInviteGuildData;
export type RawBaseGuildData = RawAnonymousGuildData | RawOAuth2GuildData;
export type RawInviteGuildData = APIPartialGuild;
export type RawOAuth2GuildData = RESTAPIPartialCurrentUserGuild;
export type RawGuildMemberData =
| APIGuildMember
| APIInteractionGuildMember
| APIInteractionDataResolvedGuildMember
| GatewayGuildMemberAddDispatchData
| GatewayGuildMemberUpdateDispatchData
| Required<RESTPatchAPICurrentGuildMemberNicknameJSONBody>
| { user: { id: Snowflake } };
export type RawThreadMemberData = APIThreadMember;
export type RawGuildPreviewData = APIGuildPreview;
export type RawGuildTemplateData = APITemplate;
export type RawIntegrationData = APIGuildIntegration;
export type RawInteractionData = GatewayInteractionCreateDispatchData;
export type RawCommandInteractionData = APIApplicationCommandInteraction;
export type RawMessageComponentInteractionData = APIMessageComponentInteraction;
export type RawMessageButtonInteractionData = APIMessageButtonInteractionData;
export type RawMessageSelectMenuInteractionData = APIMessageSelectMenuInteractionData;
export type RawInviteData =
| APIExtendedInvite
| APIInvite
| (GatewayInviteCreateDispatchData & { channel: GuildChannel; guild: Guild })
| (GatewayInviteDeleteDispatchData & { channel: GuildChannel; guild: Guild });
export type RawInviteStageInstance = APIInviteStageInstance;
export type RawMessageData = APIMessage;
export type RawPartialMessageData = GatewayMessageUpdateDispatchData;
export type RawMessageAttachementData = APIAttachment;
export type RawMessagePayloadData =
| RESTPostAPIChannelMessageJSONBody
| RESTPatchAPIChannelMessageJSONBody
| RESTPostAPIWebhookWithTokenJSONBody
| RESTPatchAPIWebhookWithTokenJSONBody
| RESTPostAPIInteractionCallbackFormDataBody
| RESTPatchAPIInteractionOriginalResponseJSONBody
| RESTPostAPIInteractionFollowupJSONBody
| RESTPatchAPIInteractionFollowupJSONBody;
export type RawMessageReactionData = APIReaction | GatewayMessageReactionAddDispatchData;
export type RawPermissionOverwriteData = APIOverwrite | PermissionOverwrites;
export type RawPresenceData = GatewayPresenceUpdate;
export type RawRoleData = APIRole;
export type RawRichPresenceAssets = GatewayActivityAssets;
export type RawStageInstanceData =
| APIStageInstance
| (Partial<APIStageInstance> & Pick<APIStageInstance, 'id' | 'channel_id' | 'guild_id'>);
export type RawStickerData = APISticker | APIStickerItem;
export type RawStickerPackData = APIStickerPack;
export type RawTeamData = APITeam;
export type RawTeamMemberData = APITeamMember;
export type RawTypingData = GatewayTypingStartDispatchData;
export type RawUserData =
| (APIUser & { member?: Omit<APIGuildMember, 'user'> })
| (GatewayPresenceUpdate['user'] & Pick<APIUser, 'username'>);
export type RawVoiceRegionData = APIVoiceRegion;
export type RawVoiceStateData = GatewayVoiceState | Omit<GatewayVoiceState, 'guild_id'>;
export type RawWebhookData =
| APIWebhook
| RESTGetAPIWebhookWithTokenResult
| (Partial<APIWebhook> & Required<Pick<APIWebhook, 'id' | 'guild_id'>>);
export type RawWelcomeChannelData = APIGuildWelcomeScreenChannel;
export type RawWelcomeScreenData = APIGuildWelcomeScreen;
export type RawWidgetData = APIGuildWidget;
export type RawWidgetMemberData = APIGuildWidgetMember;

View File

@@ -54,7 +54,7 @@ import {
Typing,
User,
VoiceChannel,
} from '..';
} from '.';
const client: Client = new Client({
intents: Intents.FLAGS.GUILDS,