feat: Guild Forum channel

https://github.com/discordjs/discord.js/pull/8651
This commit is contained in:
March 7th
2022-10-03 19:25:39 +07:00
parent 5e715fad5e
commit 2fb09d7da6
23 changed files with 821 additions and 120 deletions

View File

@@ -158,9 +158,8 @@ class ThreadChannel extends Channel {
if ('message_count' in data) {
/**
* The approximate count of messages in this thread
* <info>This stops counting at 50. If you need an approximate value higher than that, use
* `ThreadChannel#messages.cache.size`</info>
* <info>Threads created before July 1, 2022 may have an inaccurate count.
* If you need an approximate value higher than that, use `ThreadChannel#messages.cache.size`</info>
* @type {?number}
*/
this.messageCount = data.message_count;
@@ -180,6 +179,27 @@ class ThreadChannel extends Channel {
this.memberCount ??= null;
}
if ('total_message_sent' in data) {
/**
* The number of messages ever sent in a thread, similar to {@link ThreadChannel#messageCount} except it
* will not decrement whenever a message is deleted
* @type {?number}
*/
this.totalMessageSent = data.total_message_sent;
} else {
this.totalMessageSent ??= null;
}
if ('applied_tags' in data) {
/**
* The tags applied to this thread
* @type {Snowflake[]}
*/
this.appliedTags = data.applied_tags;
} else {
this.appliedTags ??= [];
}
if (data.member && this.client.user) this.members._add({ user_id: this.client.user.id, ...data.member });
if (data.messages) for (const message of data.messages) this.messages._add(message);
}
@@ -225,7 +245,7 @@ class ThreadChannel extends Channel {
/**
* The parent channel of this thread
* @type {?(NewsChannel|TextChannel)}
* @type {?(NewsChannel|TextChannel|ForumChannel)}
* @readonly
*/
get parent() {
@@ -280,14 +300,16 @@ class ThreadChannel extends Channel {
/**
* Fetches the message that started this thread, if any.
* <info>This only works when the thread started from a message in the parent channel, otherwise the promise will
* reject. If you just need the id of that message, use {@link ThreadChannel#id} instead.</info>
* <info>The `Promise` will reject if the original message in a forum post is deleted
* or when the original message in the parent channel is deleted.
* If you just need the id of that message, use {@link ThreadChannel#id} instead.</info>
* @param {BaseFetchOptions} [options] Additional options for this fetch
* @returns {Promise<Message|null>}
*/
// eslint-disable-next-line require-await
async fetchStarterMessage(options) {
return this.parent?.messages.fetch(this.id, options) ?? null;
const channel = this.parent?.type === 'GUILD_FORUM' ? this : this.parent;
return channel?.messages.fetch({ message: this.id, ...options }) ?? null;
}
/**
@@ -326,6 +348,7 @@ class ThreadChannel extends Channel {
rate_limit_per_user: data.rateLimitPerUser,
locked: data.locked,
invitable: this.type === 'GUILD_PRIVATE_THREAD' ? data.invitable : undefined,
applied_tags: data.appliedTags,
},
reason,
});
@@ -333,6 +356,16 @@ 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<GuildForumThreadChannel>}
*/
setAppliedTags(appliedTags, reason) {
return this.edit({ appliedTags, reason });
}
/**
* Sets whether the thread is archived.
* @param {boolean} [archived=true] Whether the thread is archived