feat(ForumChannel): setDefaultForumLayout & fix bug
This commit is contained in:
parent
67ab8277ed
commit
ebdd92240b
@ -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,
|
||||
});
|
||||
|
@ -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<Snowflake, OverwriteResolvable>} [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
|
||||
*/
|
||||
|
||||
|
@ -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<ForumChannel>}
|
||||
*/
|
||||
setAvailableTags(availableTags, reason) {
|
||||
return this.edit({ availableTags, reason });
|
||||
return this.edit({ availableTags }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,7 +166,7 @@ class ForumChannel extends GuildChannel {
|
||||
* @returns {Promise<ForumChannel>}
|
||||
*/
|
||||
setDefaultReactionEmoji(defaultReactionEmoji, reason) {
|
||||
return this.edit({ defaultReactionEmoji, reason });
|
||||
return this.edit({ defaultReactionEmoji }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -171,7 +176,7 @@ class ForumChannel extends GuildChannel {
|
||||
* @returns {Promise<ForumChannel>}
|
||||
*/
|
||||
setDefaultThreadRateLimitPerUser(defaultThreadRateLimitPerUser, reason) {
|
||||
return this.edit({ defaultThreadRateLimitPerUser, reason });
|
||||
return this.edit({ defaultThreadRateLimitPerUser }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,7 +186,17 @@ class ForumChannel extends GuildChannel {
|
||||
* @returns {Promise<ForumChannel>}
|
||||
*/
|
||||
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<ForumChannel>}
|
||||
*/
|
||||
setDefaultForumLayout(defaultForumLayout, reason) {
|
||||
return this.edit({ defaultForumLayout }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -215,7 +230,7 @@ class ForumChannel extends GuildChannel {
|
||||
* @returns {Promise<ForumChannel>}
|
||||
*/
|
||||
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
|
||||
|
@ -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) {
|
||||
|
6
typings/enums.d.ts
vendored
6
typings/enums.d.ts
vendored
@ -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,
|
||||
|
6
typings/index.d.ts
vendored
6
typings/index.d.ts
vendored
@ -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<this>;
|
||||
public setDefaultReactionEmoji(emojiId: DefaultReactionEmoji | null, reason?: string): Promise<this>;
|
||||
public setDefaultThreadRateLimitPerUser(rateLimit: number, reason?: string): Promise<this>;
|
||||
@ -7273,6 +7278,7 @@ export class ForumChannel extends TextBasedChannelMixin(GuildChannel, [
|
||||
): Promise<this>;
|
||||
public setTopic(topic: string | null, reason?: string): Promise<this>;
|
||||
public setDefaultSortOrder(defaultSortOrder: SortOrderType | null, reason?: string): Promise<this>;
|
||||
public setDefaultForumLayout(defaultForumLayout: ForumLayoutType, reason?: string): Promise<this>;
|
||||
}
|
||||
|
||||
export class GuildTextThreadManager<AllowedThreadType> extends ThreadManager {
|
||||
|
Loading…
Reference in New Issue
Block a user