From 316a91d3617f8f72962ff6f7d7faa3c8181572e1 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Wed, 21 Sep 2022 22:45:02 +0100 Subject: [PATCH 1/3] fix(ForumChannel): implement missing properties and methods --- .../discord.js/src/structures/ForumChannel.js | 97 ++++++++++++++++++- packages/discord.js/typings/index.d.ts | 23 ++++- 2 files changed, 113 insertions(+), 7 deletions(-) diff --git a/packages/discord.js/src/structures/ForumChannel.js b/packages/discord.js/src/structures/ForumChannel.js index a19ab19a43b8..f3e8aaed551a 100644 --- a/packages/discord.js/src/structures/ForumChannel.js +++ b/packages/discord.js/src/structures/ForumChannel.js @@ -1,6 +1,7 @@ 'use strict'; const GuildChannel = require('./GuildChannel'); +const TextBasedChannel = require('./interfaces/TextBasedChannel'); const GuildForumThreadManager = require('../managers/GuildForumThreadManager'); const { transformAPIGuildForumTag, transformAPIGuildDefaultReaction } = require('../util/Channels'); @@ -94,6 +95,34 @@ class ForumChannel extends GuildChannel { } else { this.rateLimitPerUser ??= null; } + + if ('default_auto_archive_duration' in data) { + /** + * The default auto archive duration for newly created threads in this channel. + * @type {?ThreadAutoArchiveDuration} + */ + this.defaultAutoArchiveDuration = data.default_auto_archive_duration; + } else { + this.defaultAutoArchiveDuration ??= null; + } + + if ('nsfw' in data) { + /** + * If this channel is considered NSFW. + * @type {boolean} + */ + this.nsfw = data.nsfw; + } else { + this.nsfw ??= false; + } + + if ('topic' in data) { + /** + * The topic of this channel. + * @type {?string} + */ + this.topic = data.topic; + } } /** @@ -127,14 +156,72 @@ class ForumChannel extends GuildChannel { } /** - * Sets the rate limit per user (slowmode) for this channel - * @param {?number} rateLimitPerUser The rate limit to set on this channel - * @param {string} [reason] Reason for changing the rate limit + * Creates an invite to this guild channel. + * @param {CreateInviteOptions} [options={}] The options for creating the invite + * @returns {Promise} + * @example + * // Create an invite to a channel + * channel.createInvite() + * .then(invite => console.log(`Created an invite with a code of ${invite.code}`)) + * .catch(console.error); + */ + createInvite(options) { + return this.guild.invites.create(this.id, options); + } + + /** + * Fetches a collection of invites to this guild channel. + * Resolves with a collection mapping invites by their codes. + * @param {boolean} [cache=true] Whether or not to cache the fetched invites + * @returns {Promise>} + */ + fetchInvites(cache = true) { + return this.guild.invites.fetch({ channelId: this.id, cache }); + } + + /** + * Sets the default auto archive duration for all newly created threads in this channel. + * @param {ThreadAutoArchiveDuration} defaultAutoArchiveDuration The new default auto archive duration + * @param {string} [reason] Reason for changing the channel's default auto archive duration * @returns {Promise} */ - setRateLimitPerUser(rateLimitPerUser, reason) { - return this.edit({ rateLimitPerUser, reason }); + setDefaultAutoArchiveDuration(defaultAutoArchiveDuration, reason) { + return this.edit({ defaultAutoArchiveDuration, reason }); } + + /** + * Sets a new topic for the guild channel. + * @param {?string} topic The new topic for the guild channel + * @param {string} [reason] Reason for changing the guild channel's topic + * @returns {Promise} + * @example + * // Set a new channel topic + * channel.setTopic('needs more rate limiting') + * .then(newChannel => console.log(`Channel's new topic is ${newChannel.topic}`)) + * .catch(console.error); + */ + setTopic(topic, reason) { + return this.edit({ topic, reason }); + } + + // These are here only for documentation purposes - they are implemented by TextBasedChannel + /* eslint-disable no-empty-function */ + createWebhook() {} + fetchWebhooks() {} + setNSFW() {} + setRateLimitPerUser() {} } +TextBasedChannel.applyToClass(ForumChannel, true, [ + 'send', + 'lastMessage', + 'lastPinAt', + 'bulkDelete', + 'sendTyping', + 'createMessageCollector', + 'awaitMessages', + 'createMessageComponentCollector', + 'awaitMessageComponent', +]); + module.exports = ForumChannel; diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index fa949af30c6e..49c9a8310431 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2071,18 +2071,37 @@ export interface DefaultReactionEmoji { name: string | null; } -export class ForumChannel extends GuildChannel { +export class ForumChannel extends TextBasedChannelMixin(GuildChannel, true, [ + 'send', + 'lastMessage', + 'lastPinAt', + 'bulkDelete', + 'sendTyping', + 'createMessageCollector', + 'awaitMessages', + 'createMessageComponentCollector', + 'awaitMessageComponent', +]) { public type: ChannelType.GuildForum; public threads: GuildForumThreadManager; public availableTags: GuildForumTag[]; public defaultReactionEmoji: DefaultReactionEmoji | null; public defaultThreadRateLimitPerUser: number | null; public rateLimitPerUser: number | null; + public defaultAutoArchiveDuration: ThreadAutoArchiveDuration | null; + public nsfw: boolean; + public topic: string | null; public setAvailableTags(tags: GuildForumTagData[], reason?: string): Promise; public setDefaultReactionEmoji(emojiId: DefaultReactionEmoji | null, reason?: string): Promise; public setDefaultThreadRateLimitPerUser(rateLimit: number, reason?: string): Promise; - public setRateLimitPerUser(rateLimitPerUser: number | null, reason?: string): Promise; + public createInvite(options?: CreateInviteOptions): Promise; + public fetchInvites(cache?: boolean): Promise>; + public setDefaultAutoArchiveDuration( + defaultAutoArchiveDuration: ThreadAutoArchiveDuration, + reason?: string, + ): Promise; + public setTopic(topic: string | null, reason?: string): Promise; } export class PermissionOverwrites extends Base { From 44b959baef22142c6c3c076b13fed0a30f649de1 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Thu, 22 Sep 2022 10:48:46 +0100 Subject: [PATCH 2/3] refactor(ForumChannel): remove redundant default --- packages/discord.js/src/structures/ForumChannel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/src/structures/ForumChannel.js b/packages/discord.js/src/structures/ForumChannel.js index f3e8aaed551a..9d0105acaa65 100644 --- a/packages/discord.js/src/structures/ForumChannel.js +++ b/packages/discord.js/src/structures/ForumChannel.js @@ -175,7 +175,7 @@ class ForumChannel extends GuildChannel { * @param {boolean} [cache=true] Whether or not to cache the fetched invites * @returns {Promise>} */ - fetchInvites(cache = true) { + fetchInvites(cache) { return this.guild.invites.fetch({ channelId: this.id, cache }); } From 5dee35efb800eceb6ddfe1f68feff70d708e7970 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Thu, 22 Sep 2022 10:49:53 +0100 Subject: [PATCH 3/3] docs(ForumChannel): remove superfluous wording --- packages/discord.js/src/structures/ForumChannel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/src/structures/ForumChannel.js b/packages/discord.js/src/structures/ForumChannel.js index 9d0105acaa65..afc632b7ea7a 100644 --- a/packages/discord.js/src/structures/ForumChannel.js +++ b/packages/discord.js/src/structures/ForumChannel.js @@ -172,7 +172,7 @@ class ForumChannel extends GuildChannel { /** * Fetches a collection of invites to this guild channel. * Resolves with a collection mapping invites by their codes. - * @param {boolean} [cache=true] Whether or not to cache the fetched invites + * @param {boolean} [cache=true] Whether to cache the fetched invites * @returns {Promise>} */ fetchInvites(cache) {