From eb28ee7905eee248b9ccd248f7d8275933dd0637 Mon Sep 17 00:00:00 2001 From: izexi <43889168+izexi@users.noreply.github.com> Date: Fri, 22 Jan 2021 16:46:55 +0000 Subject: [PATCH] fix(typings): return types for 'Webhook(Client)#send()' (#4876) * feat(Typings): add 'APIRawMessage' interface * fix(Typings): return type for WebhookFields#send() * fix(Typings): types for APIRawMessage props * refactor(Typings): exclude oauth props from API * feat(Typings): add WebhookRawMessageResponse type * refactor(Typings): use WebhookRawMessageResponse --- typings/index.d.ts | 118 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 112 insertions(+), 6 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index a346ca51f64e..d446d99ac7e6 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2092,18 +2092,25 @@ declare module 'discord.js' { edit(options: WebhookEditData): Promise; send( content: APIMessageContentResolvable | (WebhookMessageOptions & { split?: false }) | MessageAdditions, - ): Promise; - send(options: WebhookMessageOptions & { split: true | SplitOptions }): Promise; - send(options: WebhookMessageOptions | APIMessage): Promise; + ): Promise; + send( + options: WebhookMessageOptions & { split: true | SplitOptions }, + ): Promise<(Message | WebhookRawMessageResponse)[]>; + send( + options: WebhookMessageOptions | APIMessage, + ): Promise; send( content: StringResolvable, options: (WebhookMessageOptions & { split?: false }) | MessageAdditions, - ): Promise; + ): Promise; send( content: StringResolvable, options: WebhookMessageOptions & { split: true | SplitOptions }, - ): Promise; - send(content: StringResolvable, options: WebhookMessageOptions): Promise; + ): Promise<(Message | WebhookRawMessageResponse)[]>; + send( + content: StringResolvable, + options: WebhookMessageOptions, + ): Promise; sendSlackMessage(body: object): Promise; } @@ -2198,6 +2205,95 @@ declare module 'discord.js' { type APIMessageContentResolvable = string | number | boolean | bigint | symbol | readonly StringResolvable[]; + interface APIRawMessage { + id: Snowflake; + type: number; + content: string; + channel_id: Snowflake; + author: { + bot?: true; + id: Snowflake; + username: string; + avatar: string | null; + discriminator: string; + }; + attachments: { + id: Snowflake; + filename: string; + size: number; + url: string; + proxy_url: string; + height: number | null; + width: number | null; + }[]; + embeds: { + title?: string; + type?: 'rich' | 'image' | 'video' | 'gifv' | 'article' | 'link'; + description?: string; + url?: string; + timestamp?: string; + color?: number; + footer?: { + text: string; + icon_url?: string; + proxy_icon_url?: string; + }; + image?: { + url?: string; + proxy_url?: string; + height?: number; + width?: number; + }; + thumbnail?: { + url?: string; + proxy_url?: string; + height?: number; + width?: number; + }; + video?: { + url?: string; + height?: number; + width?: number; + }; + provider?: { name?: string; url?: string }; + author?: { + name?: string; + url?: string; + icon_url?: string; + proxy_icon_url?: string; + }; + fields?: { + name: string; + value: string; + inline?: boolean; + }[]; + }[]; + mentions: { + id: Snowflake; + username: string; + discriminator: string; + avatar: string | null; + bot?: true; + public_flags?: number; + member?: { + nick: string | null; + roles: Snowflake[]; + joined_at: string; + premium_since?: string | null; + deaf: boolean; + mute: boolean; + }; + }[]; + mention_roles: Snowflake[]; + pinned: boolean; + mention_everyone: boolean; + tts: boolean; + timestamp: string; + edited_timestamp: string | null; + flags: number; + webhook_id: Snowflake; + } + interface ApplicationAsset { name: string; id: Snowflake; @@ -3207,6 +3303,16 @@ declare module 'discord.js' { split?: boolean | SplitOptions; } + type WebhookRawMessageResponse = Omit & { + author: { + bot: true; + id: Snowflake; + username: string; + avatar: string | null; + discriminator: '0000'; + }; + }; + type WebhookTypes = 'Incoming' | 'Channel Follower'; interface WebSocketOptions {