Discord.js v13.7
This commit is contained in:
@@ -6,6 +6,7 @@ const { RangeError } = require('../errors');
|
||||
const MessageManager = require('../managers/MessageManager');
|
||||
const ThreadMemberManager = require('../managers/ThreadMemberManager');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const { resolveAutoArchiveMaxLimit } = require('../util/Util');
|
||||
|
||||
/**
|
||||
* Represents a thread channel on Discord.
|
||||
@@ -100,6 +101,11 @@ class ThreadChannel extends Channel {
|
||||
* @type {?number}
|
||||
*/
|
||||
this.archiveTimestamp = new Date(data.thread_metadata.archive_timestamp).getTime();
|
||||
|
||||
if ('create_timestamp' in data.thread_metadata) {
|
||||
// Note: this is needed because we can't assign directly to getters
|
||||
this._createdTimestamp = Date.parse(data.thread_metadata.create_timestamp);
|
||||
}
|
||||
} else {
|
||||
this.locked ??= null;
|
||||
this.archived ??= null;
|
||||
@@ -108,6 +114,8 @@ class ThreadChannel extends Channel {
|
||||
this.invitable ??= null;
|
||||
}
|
||||
|
||||
this._createdTimestamp ??= this.type === 'GUILD_PRIVATE_THREAD' ? super.createdTimestamp : null;
|
||||
|
||||
if ('owner_id' in data) {
|
||||
/**
|
||||
* The id of the member who created this thread
|
||||
@@ -176,6 +184,16 @@ class ThreadChannel extends Channel {
|
||||
if (data.messages) for (const message of data.messages) this.messages._add(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* The timestamp when this thread was created. This isn't available for threads
|
||||
* created before 2022-01-09
|
||||
* @type {?number}
|
||||
* @readonly
|
||||
*/
|
||||
get createdTimestamp() {
|
||||
return this._createdTimestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* A collection of associated guild member objects of this thread's members
|
||||
* @type {Collection<Snowflake, GuildMember>}
|
||||
@@ -196,6 +214,15 @@ class ThreadChannel extends Channel {
|
||||
return new Date(this.archiveTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* The time the thread was created at
|
||||
* @type {?Date}
|
||||
* @readonly
|
||||
*/
|
||||
get createdAt() {
|
||||
return this.createdTimestamp && new Date(this.createdTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* The parent channel of this thread
|
||||
* @type {?(NewsChannel|TextChannel)}
|
||||
@@ -288,14 +315,8 @@ class ThreadChannel extends Channel {
|
||||
*/
|
||||
async edit(data, reason) {
|
||||
let autoArchiveDuration = data.autoArchiveDuration;
|
||||
if (data.autoArchiveDuration === 'MAX') {
|
||||
autoArchiveDuration = 1440;
|
||||
if (this.guild.features.includes('SEVEN_DAY_THREAD_ARCHIVE')) {
|
||||
autoArchiveDuration = 10080;
|
||||
} else if (this.guild.features.includes('THREE_DAY_THREAD_ARCHIVE')) {
|
||||
autoArchiveDuration = 4320;
|
||||
}
|
||||
}
|
||||
if (autoArchiveDuration === 'MAX') autoArchiveDuration = resolveAutoArchiveMaxLimit(this.guild);
|
||||
|
||||
const newData = await this.client.api.channels(this.id).patch({
|
||||
data: {
|
||||
name: (data.name ?? this.name).trim(),
|
||||
@@ -487,7 +508,15 @@ class ThreadChannel extends Channel {
|
||||
* @readonly
|
||||
*/
|
||||
get unarchivable() {
|
||||
return this.archived && (this.locked ? this.manageable : this.sendable);
|
||||
return this.archived && this.sendable && (!this.locked || this.manageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this thread is a private thread
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isPrivate() {
|
||||
return this.type === 'GUILD_PRIVATE_THREAD';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -501,7 +530,7 @@ class ThreadChannel extends Channel {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async delete(reason) {
|
||||
await this.client.api.channels(this.id).delete({ reason });
|
||||
await this.guild.channels.delete(this.id, reason);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user