From f8246be0aac5f5dcc39a127a8551f396a04f2adb Mon Sep 17 00:00:00 2001
From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com>
Date: Wed, 26 Oct 2022 19:21:40 +0700
Subject: [PATCH] feat: ForumChannel
Backport https://github.com/discordjs/discord.js/pull/8786
---
src/managers/GuildForumThreadManager.js | 4 +--
src/structures/ThreadChannel.js | 48 ++++++++++++++++---------
2 files changed, 32 insertions(+), 20 deletions(-)
diff --git a/src/managers/GuildForumThreadManager.js b/src/managers/GuildForumThreadManager.js
index b75332e..83b1412 100644
--- a/src/managers/GuildForumThreadManager.js
+++ b/src/managers/GuildForumThreadManager.js
@@ -55,8 +55,6 @@ class GuildForumThreadManager extends ThreadManager {
rateLimitPerUser,
appliedTags,
} = {}) {
- let path = this.client.api.channels(this.channel.id);
-
if (!message) {
throw new TypeError('GUILD_FORUM_MESSAGE_REQUIRED');
}
@@ -73,7 +71,7 @@ class GuildForumThreadManager extends ThreadManager {
if (autoArchiveDuration === 'MAX') autoArchiveDuration = resolveAutoArchiveMaxLimit(this.channel.guild);
- const data = await path.threads.post({
+ const data = await this.client.api.channels(this.channel.id).threads.post({
data: {
name,
auto_archive_duration: autoArchiveDuration,
diff --git a/src/structures/ThreadChannel.js b/src/structures/ThreadChannel.js
index 28b74de..8bb5b8f 100644
--- a/src/structures/ThreadChannel.js
+++ b/src/structures/ThreadChannel.js
@@ -3,9 +3,9 @@
const { Channel } = require('./Channel');
const TextBasedChannel = require('./interfaces/TextBasedChannel');
const { RangeError } = require('../errors');
-const InteractionManager = require('../managers/InteractionManager');
const MessageManager = require('../managers/MessageManager');
const ThreadMemberManager = require('../managers/ThreadMemberManager');
+const ChannelFlags = require('../util/ChannelFlags');
const Permissions = require('../util/Permissions');
const { resolveAutoArchiveMaxLimit } = require('../util/Util');
@@ -36,12 +36,6 @@ class ThreadChannel extends Channel {
*/
this.messages = new MessageManager(this);
- /**
- * A manager of the interactions sent to this channel
- * @type {InteractionManager}
- */
- this.interactions = new InteractionManager(this);
-
/**
* A manager of the members that are part of this thread
* @type {ThreadMemberManager}
@@ -329,6 +323,7 @@ class ThreadChannel extends Channel {
* @property {number} [rateLimitPerUser] The rate limit per user (slowmode) for the thread in seconds
* @property {boolean} [locked] Whether the thread is locked
* @property {boolean} [invitable] Whether non-moderators can add other non-moderators to a thread
+ * @property {ChannelFlagsResolvable} [flags] The flags to set on the channel
* Can only be edited on `GUILD_PRIVATE_THREAD`
*/
@@ -356,6 +351,7 @@ class ThreadChannel extends Channel {
locked: data.locked,
invitable: this.type === 'GUILD_PRIVATE_THREAD' ? data.invitable : undefined,
applied_tags: data.appliedTags,
+ flags: 'flags' in data ? ChannelFlags.resolve(data.flags) : undefined,
},
reason,
});
@@ -363,16 +359,6 @@ class ThreadChannel extends Channel {
return this.client.actions.ChannelUpdate.handle(newData).updated;
}
- /**
- * Set the applied tags for this channel (only applicable to forum threads)
- * @param {Snowflake[]} appliedTags The tags to set for this channel
- * @param {string} [reason] Reason for changing the thread's applied tags
- * @returns {Promise}
- */
- setAppliedTags(appliedTags, reason) {
- return this.edit({ appliedTags, reason });
- }
-
/**
* Sets whether the thread is archived.
* @param {boolean} [archived=true] Whether the thread is archived
@@ -459,6 +445,34 @@ class ThreadChannel extends Channel {
return this.edit({ rateLimitPerUser }, reason);
}
+ /**
+ * Pins this thread from the forum channel.
+ * @param {string} [reason] Reason for pinning
+ * @returns {Promise}
+ */
+ pin(reason) {
+ return this.edit({ flags: this.flags.add(ChannelFlags.FLAGS.PINNED), reason });
+ }
+
+ /**
+ * Unpins this thread from the forum channel.
+ * @param {string} [reason] Reason for unpinning
+ * @returns {Promise}
+ */
+ unpin(reason) {
+ return this.edit({ flags: this.flags.remove(ChannelFlags.FLAGS.PINNED), reason });
+ }
+
+ /**
+ * Set the applied tags for this channel (only applicable to forum threads)
+ * @param {Snowflake[]} appliedTags The tags to set for this channel
+ * @param {string} [reason] Reason for changing the thread's applied tags
+ * @returns {Promise}
+ */
+ setAppliedTags(appliedTags, reason) {
+ return this.edit({ appliedTags, reason });
+ }
+
/**
* Whether the client user is a member of the thread.
* @type {boolean}