Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ForumChannel): add defaultSortOrder #8633

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -53,6 +53,7 @@ class CategoryChannelChildManager extends DataManager {
* @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 {string} [reason] Reason for creating the new channel
*/

Expand Down
4 changes: 4 additions & 0 deletions packages/discord.js/src/managers/GuildChannelManager.js
Expand Up @@ -141,6 +141,7 @@ class GuildChannelManager extends CachedManager {
videoQualityMode,
availableTags,
defaultReactionEmoji,
defaultSortOrder,
reason,
}) {
parent &&= this.client.channels.resolveId(parent);
Expand All @@ -162,6 +163,7 @@ class GuildChannelManager extends CachedManager {
video_quality_mode: videoQualityMode,
available_tags: availableTags?.map(availableTag => transformGuildForumTag(availableTag)),
default_reaction_emoji: defaultReactionEmoji && transformGuildDefaultReaction(defaultReactionEmoji),
default_sort_order: defaultSortOrder,
},
reason,
});
Expand Down Expand Up @@ -229,6 +231,7 @@ class GuildChannelManager extends CachedManager {
* @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 {ChannelFlagsResolvable} [flags] The flags to set on the channel
* @property {?SortOrderType} [defaultSortOrder] The default sort order mode to set on the channel
* @property {string} [reason] Reason for editing this channel
*/

Expand Down Expand Up @@ -289,6 +292,7 @@ class GuildChannelManager extends CachedManager {
default_reaction_emoji: data.defaultReactionEmoji && transformGuildDefaultReaction(data.defaultReactionEmoji),
default_thread_rate_limit_per_user: data.defaultThreadRateLimitPerUser,
flags: 'flags' in data ? ChannelFlagsBitField.resolve(data.flags) : undefined,
default_sort_order: data.defaultSortOrder,
},
reason: data.reason,
});
Expand Down
20 changes: 20 additions & 0 deletions packages/discord.js/src/structures/ForumChannel.js
Expand Up @@ -124,6 +124,16 @@ class ForumChannel extends GuildChannel {
*/
this.topic = data.topic;
}

if ('default_sort_order' in data) {
/**
* The default sort order mode used to order posts
* @type {?SortOrderType}
*/
this.defaultSortOrder = data.default_sort_order;
} else {
this.defaultSortOrder ??= null;
}
}

/**
Expand Down Expand Up @@ -205,6 +215,16 @@ class ForumChannel extends GuildChannel {
return this.edit({ topic, reason });
}

/**
* Sets the default sort order mode used to order posts
* @param {?SortOrderType} defaultSortOrder The default sort order mode to set on this channel
* @param {string} [reason] Reason for changing the default sort order
* @returns {Promise<ForumChannel>}
*/
setDefaultSortOrder(defaultSortOrder, reason) {
return this.edit({ defaultSortOrder, reason });
}

// These are here only for documentation purposes - they are implemented by TextBasedChannel
/* eslint-disable no-empty-function */
createWebhook() {}
Expand Down
5 changes: 5 additions & 0 deletions packages/discord.js/src/util/APITypes.js
Expand Up @@ -333,6 +333,11 @@
* @see {@link https://discord-api-types.dev/api/discord-api-types-rest/common/enum/RESTJSONErrorCodes}
*/

/**
* @external SortOrderType
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/SortOrderType}
*/

/**
* @external StageInstancePrivacyLevel
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/StageInstancePrivacyLevel}
Expand Down
5 changes: 5 additions & 0 deletions packages/discord.js/typings/index.d.ts
Expand Up @@ -125,6 +125,7 @@ import {
AuditLogOptionsType,
TextChannelType,
ChannelFlags,
SortOrderType,
} from 'discord-api-types/v10';
import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
Expand Down Expand Up @@ -2097,6 +2098,7 @@ export class ForumChannel extends TextBasedChannelMixin(GuildChannel, true, [
public defaultAutoArchiveDuration: ThreadAutoArchiveDuration | null;
public nsfw: boolean;
public topic: string | null;
public defaultSortOrder: SortOrderType | null;

public setAvailableTags(tags: GuildForumTagData[], reason?: string): Promise<this>;
public setDefaultReactionEmoji(emojiId: DefaultReactionEmoji | null, reason?: string): Promise<this>;
Expand All @@ -2108,6 +2110,7 @@ export class ForumChannel extends TextBasedChannelMixin(GuildChannel, true, [
reason?: string,
): Promise<this>;
public setTopic(topic: string | null, reason?: string): Promise<this>;
public setDefaultSortOrder(defaultSortOrder: SortOrderType | null, reason?: string): Promise<this>;
}

export class PermissionOverwrites extends Base {
Expand Down Expand Up @@ -4251,6 +4254,7 @@ export interface CategoryCreateChannelOptions {
videoQualityMode?: VideoQualityMode;
availableTags?: GuildForumTagData[];
defaultReactionEmoji?: DefaultReactionEmoji;
defaultSortOrder?: SortOrderType;
reason?: string;
}

Expand Down Expand Up @@ -4932,6 +4936,7 @@ export interface GuildChannelEditOptions {
defaultReactionEmoji?: DefaultReactionEmoji | null;
defaultThreadRateLimitPerUser?: number;
flags?: ChannelFlagsResolvable;
defaultSortOrder?: SortOrderType | null;
reason?: string;
}

Expand Down