diff --git a/src/managers/GuildChannelManager.js b/src/managers/GuildChannelManager.js index 3c30bbc..0b4ad0d 100644 --- a/src/managers/GuildChannelManager.js +++ b/src/managers/GuildChannelManager.js @@ -10,7 +10,13 @@ const PermissionOverwrites = require('../structures/PermissionOverwrites'); const ThreadChannel = require('../structures/ThreadChannel'); const Webhook = require('../structures/Webhook'); const ChannelFlags = require('../util/ChannelFlags'); -const { ThreadChannelTypes, ChannelTypes, VideoQualityModes, SortOrderTypes } = require('../util/Constants'); +const { + ThreadChannelTypes, + ChannelTypes, + VideoQualityModes, + SortOrderTypes, + ForumLayoutTypes, +} = require('../util/Constants'); const DataResolver = require('../util/DataResolver'); const Util = require('../util/Util'); const { resolveAutoArchiveMaxLimit, transformGuildForumTag, transformGuildDefaultReaction } = require('../util/Util'); @@ -144,6 +150,7 @@ class GuildChannelManager extends CachedManager { availableTags, defaultReactionEmoji, defaultSortOrder, + defaultForumLayout, reason, } = {}, ) { @@ -155,6 +162,9 @@ class GuildChannelManager extends CachedManager { const sortMode = typeof defaultSortOrder === 'number' ? defaultSortOrder : SortOrderTypes[defaultSortOrder]; + const layoutMode = + typeof defaultForumLayout === 'number' ? defaultForumLayout : ForumLayoutTypes[defaultForumLayout]; + if (intType === ChannelTypes.GUILD_STORE && !storeChannelDeprecationEmitted) { storeChannelDeprecationEmitted = true; process.emitWarning( @@ -181,6 +191,7 @@ class GuildChannelManager extends CachedManager { available_tags: availableTags?.map(availableTag => transformGuildForumTag(availableTag)), default_reaction_emoji: defaultReactionEmoji && transformGuildDefaultReaction(defaultReactionEmoji), default_sort_order: sortMode, + default_forum_layout: layoutMode, }, reason, }); diff --git a/src/structures/CategoryChannel.js b/src/structures/CategoryChannel.js index bb5c302..831b787 100644 --- a/src/structures/CategoryChannel.js +++ b/src/structures/CategoryChannel.js @@ -30,21 +30,25 @@ class CategoryChannel extends GuildChannel { /** * Options for creating a channel using {@link CategoryChannel#createChannel}. * @typedef {Object} CategoryCreateChannelOptions + * @property {string} [name] The name of the new channel * @property {ChannelType|number} [type='GUILD_TEXT'] The type of the new channel. + * @property {number} [position] Position of the new channel * @property {string} [topic] The topic for the new channel * @property {boolean} [nsfw] Whether the new channel is NSFW * @property {number} [bitrate] Bitrate of the new channel in bits (only voice) * @property {number} [userLimit] Maximum amount of users allowed in the new channel (only voice) * @property {OverwriteResolvable[]|Collection} [permissionOverwrites] * Permission overwrites of the new channel - * @property {number} [position] Position of the new channel * @property {number} [rateLimitPerUser] The rate limit per user (slowmode) for the new channel in seconds - * @property {string} [rtcRegion] The specific region of the new channel. - * @property {VideoQualityMode} [videoQualityMode] The camera video quality mode of the voice channel - * @property {GuildForumTagData[]} [availableTags] The tags that can be used in this channel (forum only). - * @property {DefaultReactionEmoji} [defaultReactionEmoji] - * The emoji to show in the add reaction button on a thread in a guild forum channel. - * @property {SortOrderType} [defaultSortOrder] The default sort order mode used to order posts (forum only). + * @property {ThreadAutoArchiveDuration} [defaultAutoArchiveDuration] + * The default auto archive duration for all new threads in this channel + * @property {?string} [rtcRegion] The specific region of the new channel + * @property {?VideoQualityMode|number} [videoQualityMode] The camera video quality mode of the new channel + * @property {ChannelFlagsResolvable} [flags] The flags to set on the new channel + * @property {GuildForumTagData[]} [availableTags] The tags to set as available in a forum channel + * @property {?DefaultReactionEmoji} [defaultReactionEmoji] The emoji to set as the default reaction emoji + * @property {number} [defaultThreadRateLimitPerUser] The rate limit per user (slowmode) to set on forum posts + * @property {?SortOrderType} [defaultSortOrder] The default sort order mode to set on the new channel * @property {string} [reason] Reason for creating the new channel */ diff --git a/src/structures/ForumChannel.js b/src/structures/ForumChannel.js index a3a6f59..61723e4 100644 --- a/src/structures/ForumChannel.js +++ b/src/structures/ForumChannel.js @@ -4,7 +4,7 @@ const GuildChannel = require('./GuildChannel'); const TextBasedChannel = require('./interfaces/TextBasedChannel'); const GuildForumThreadManager = require('../managers/GuildForumThreadManager'); const InteractionManager = require('../managers/InteractionManager'); -const { SortOrderTypes } = require('../util/Constants'); +const { SortOrderTypes, ForumLayoutTypes } = require('../util/Constants'); const { transformAPIGuildForumTag, transformAPIGuildDefaultReaction } = require('../util/Util'); /** @@ -46,18 +46,18 @@ class ForumChannel extends GuildChannel { constructor(guild, data, client) { super(guild, data, client, false); - /** - * A manager of the threads belonging to this channel - * @type {GuildForumThreadManager} - */ - this.threads = new GuildForumThreadManager(this); - /** * A manager of the interactions sent to this channel * @type {InteractionManager} */ this.interactions = new InteractionManager(this); + /** + * A manager of the threads belonging to this channel + * @type {GuildForumThreadManager} + */ + this.threads = new GuildForumThreadManager(this); + this._patch(data); } @@ -78,9 +78,8 @@ class ForumChannel extends GuildChannel { * The emoji to show in the add reaction button on a thread in a guild forum channel * @type {?DefaultReactionEmoji} */ - this.defaultReactionEmoji = data.default_reaction_emoji - ? transformAPIGuildDefaultReaction(data.default_reaction_emoji) - : null; + this.defaultReactionEmoji = + data.default_reaction_emoji && transformAPIGuildDefaultReaction(data.default_reaction_emoji); } else { this.defaultReactionEmoji ??= null; } @@ -142,6 +141,12 @@ class ForumChannel extends GuildChannel { } else { this.defaultSortOrder ??= null; } + + /** + * The default layout type used to display posts + * @type {ForumLayoutType} + */ + this.defaultForumLayout = ForumLayoutTypes[data.default_forum_layout]; } /** @@ -151,7 +156,7 @@ class ForumChannel extends GuildChannel { * @returns {Promise} */ setAvailableTags(availableTags, reason) { - return this.edit({ availableTags, reason }); + return this.edit({ availableTags }, reason); } /** @@ -161,7 +166,7 @@ class ForumChannel extends GuildChannel { * @returns {Promise} */ setDefaultReactionEmoji(defaultReactionEmoji, reason) { - return this.edit({ defaultReactionEmoji, reason }); + return this.edit({ defaultReactionEmoji }, reason); } /** @@ -171,7 +176,7 @@ class ForumChannel extends GuildChannel { * @returns {Promise} */ setDefaultThreadRateLimitPerUser(defaultThreadRateLimitPerUser, reason) { - return this.edit({ defaultThreadRateLimitPerUser, reason }); + return this.edit({ defaultThreadRateLimitPerUser }, reason); } /** @@ -181,7 +186,17 @@ class ForumChannel extends GuildChannel { * @returns {Promise} */ setDefaultSortOrder(defaultSortOrder, reason) { - return this.edit({ defaultSortOrder, reason }); + return this.edit({ defaultSortOrder }, reason); + } + + /** + * Sets the default forum layout type used to display posts + * @param {ForumLayoutType} defaultForumLayout The default forum layout type to set on this channel + * @param {string} [reason] Reason for changing the default forum layout + * @returns {Promise} + */ + setDefaultForumLayout(defaultForumLayout, reason) { + return this.edit({ defaultForumLayout }, reason); } /** @@ -215,7 +230,7 @@ class ForumChannel extends GuildChannel { * @returns {Promise} */ setDefaultAutoArchiveDuration(defaultAutoArchiveDuration, reason) { - return this.edit({ defaultAutoArchiveDuration, reason }); + return this.edit({ defaultAutoArchiveDuration }, reason); } /** @@ -230,7 +245,7 @@ class ForumChannel extends GuildChannel { * .catch(console.error); */ setTopic(topic, reason) { - return this.edit({ topic, reason }); + return this.edit({ topic }, reason); } // These are here only for documentation purposes - they are implemented by TextBasedChannel diff --git a/src/util/Constants.js b/src/util/Constants.js index 5a6c728..07a4ad9 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -1731,6 +1731,16 @@ exports.VideoQualityModes = createEnum([null, 'AUTO', 'FULL']); */ exports.SortOrderTypes = createEnum([null, 'LATEST_ACTIVITY', 'CREATION_DATE']); +/** + * The default forum layout to set on the {@link ForumChannel} + * * NOT_SET + * * LIST_VIEW + * * GALLERY_VIEW + * @typedef {string} ForumLayoutType + * @see {@link https://discord.com/developers/docs/resources/channel/#channel-object-forum-layout-types} + */ +exports.ForumLayoutTypes = createEnum(['NOT_SET', 'LIST_VIEW', 'GALLERY_VIEW']); + exports._cleanupSymbol = Symbol('djsCleanup'); function keyMirror(arr) { diff --git a/typings/enums.d.ts b/typings/enums.d.ts index f2e96bb..fe258b0 100644 --- a/typings/enums.d.ts +++ b/typings/enums.d.ts @@ -141,6 +141,12 @@ export const enum SortOrderType { CREATION_DATE = 2, } +export const enum ForumLayoutType { + NOT_SET = 0, + LIST_VIEW = 1, + GALLERY_VIEW = 2, +} + export const enum MessageTypes { DEFAULT, RECIPIENT_ADD, diff --git a/typings/index.d.ts b/typings/index.d.ts index 70adde0..c12c51a 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -105,6 +105,7 @@ import { VideoQualityModes, SortOrderType, SelectMenuComponentTypes, + ForumLayoutType, } from './enums'; import { APIAutoModerationRule, @@ -5249,6 +5250,7 @@ export interface CategoryCreateChannelOptions { availableTags?: GuildForumTagData[]; defaultReactionEmoji?: DefaultReactionEmoji; defaultSortOrder?: SortOrderType; + defaultForumLayout?: ForumLayoutType; reason?: string; } @@ -5277,6 +5279,7 @@ export interface ChannelData { defaultReactionEmoji?: DefaultReactionEmoji; defaultThreadRateLimitPerUser?: number; defaultSortOrder?: SortOrderType | null; + defaultForumLayout?: ForumLayoutType; flags?: ChannelFlagsResolvable; } @@ -7262,6 +7265,8 @@ export class ForumChannel extends TextBasedChannelMixin(GuildChannel, [ public defaultAutoArchiveDuration: ThreadAutoArchiveDuration | null; public nsfw: boolean; public topic: string | null; + public defaultSortOrder: SortOrderType | null; + public defaultForumLayout: ForumLayoutType; public setAvailableTags(tags: GuildForumTagData[], reason?: string): Promise; public setDefaultReactionEmoji(emojiId: DefaultReactionEmoji | null, reason?: string): Promise; public setDefaultThreadRateLimitPerUser(rateLimit: number, reason?: string): Promise; @@ -7273,6 +7278,7 @@ export class ForumChannel extends TextBasedChannelMixin(GuildChannel, [ ): Promise; public setTopic(topic: string | null, reason?: string): Promise; public setDefaultSortOrder(defaultSortOrder: SortOrderType | null, reason?: string): Promise; + public setDefaultForumLayout(defaultForumLayout: ForumLayoutType, reason?: string): Promise; } export class GuildTextThreadManager extends ThreadManager {