diff --git a/packages/discord.js/src/structures/PartialGroupDMChannel.js b/packages/discord.js/src/structures/PartialGroupDMChannel.js index 935ca5f5c65cf..0e2bff1244f66 100644 --- a/packages/discord.js/src/structures/PartialGroupDMChannel.js +++ b/packages/discord.js/src/structures/PartialGroupDMChannel.js @@ -1,12 +1,14 @@ 'use strict'; const { BaseChannel } = require('./BaseChannel'); +const TextBasedChannel = require('./interfaces/TextBasedChannel'); const { DiscordjsError, ErrorCodes } = require('../errors'); const PartialGroupDMMessageManager = require('../managers/PartialGroupDMMessageManager'); /** * Represents a Partial Group DM Channel on Discord. * @extends {BaseChannel} + * @implements {TextBasedChannel} */ class PartialGroupDMChannel extends BaseChannel { constructor(client, data) { @@ -70,21 +72,12 @@ class PartialGroupDMChannel extends BaseChannel { * The timestamp when the last pinned message was pinned, if there was one * @type {?number} */ - this.lastPinTimestamp = data.last_pin_timestamp; + this.lastPinTimestamp = Date.parse(data.last_pin_timestamp); } else { this.lastPinTimestamp ??= null; } } - /** - * The date when the last pinned message was pinned, if there was one - * @type {?Date} - * @readonly - */ - get lastPinAt() { - return this.lastPinTimestamp && new Date(this.lastPinTimestamp); - } - /** * The URL to this channel's icon. * @param {ImageURLOptions} [options={}] Options for the image URL @@ -114,6 +107,25 @@ class PartialGroupDMChannel extends BaseChannel { fetch() { return Promise.reject(new DiscordjsError(ErrorCodes.FetchGroupDMChannel)); } + + // These are here only for documentation purposes - they are implemented by TextBasedChannel + /* eslint-disable no-empty-function */ + get lastMessage() {} + get lastPinAt() {} + createMessageComponentCollector() {} + awaitMessageComponent() {} } +TextBasedChannel.applyToClass(PartialGroupDMChannel, true, [ + 'bulkDelete', + 'send', + 'sendTyping', + 'createMessageCollector', + 'awaitMessages', + 'fetchWebhooks', + 'createWebhook', + 'setRateLimitPerUser', + 'setNSFW', +]); + module.exports = PartialGroupDMChannel; diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 88151c04daece..f5b685805041f 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1334,7 +1334,7 @@ export interface ResolvedFile { // tslint:disable-next-line no-empty-interface export interface DMChannel extends Omit< - TextBasedChannelFields, + TextBasedChannelFields, 'bulkDelete' | 'fetchWebhooks' | 'createWebhook' | 'setRateLimitPerUser' | 'setNSFW' > {} export class DMChannel extends BaseChannel { @@ -2582,6 +2582,19 @@ export class OAuth2Guild extends BaseGuild { public permissions: Readonly; } +export interface PartialGroupDMChannel + extends Omit< + TextBasedChannelFields, + | 'bulkDelete' + | 'send' + | 'sendTyping' + | 'createMessageCollector' + | 'awaitMessages' + | 'fetchWebhooks' + | 'createWebhook' + | 'setRateLimitPerUser' + | 'setNSFW' + > {} export class PartialGroupDMChannel extends BaseChannel { private constructor(client: Client, data: RawPartialGroupDMChannelData); public type: ChannelType.GroupDM; @@ -2589,11 +2602,7 @@ export class PartialGroupDMChannel extends BaseChannel { public name: string | null; public icon: string | null; public recipients: PartialRecipient[]; - public messages: PartialGroupDMMessageManager; public ownerId: Snowflake | null; - public lastMessageId: Snowflake | null; - public lastPinTimestamp: number | null; - get lastPinAt(): Date | null; public iconURL(options?: ImageURLOptions): string | null; public fetchOwner(options?: BaseFetchOptions): Promise; public toString(): ChannelMention; @@ -4722,13 +4731,13 @@ export interface PartialTextBasedChannelFields>; } -export interface TextBasedChannelFields +export interface TextBasedChannelFields extends PartialTextBasedChannelFields { lastMessageId: Snowflake | null; get lastMessage(): Message | null; lastPinTimestamp: number | null; get lastPinAt(): Date | null; - messages: If; + messages: If>; awaitMessageComponent( options?: AwaitMessageCollectorOptionsParams, ): Promise;