From 136490a9a998864ef81cdb0fbeb8863fb459215e Mon Sep 17 00:00:00 2001
From: Rodry <38259440+ImRodry@users.noreply.github.com>
Date: Wed, 28 Jul 2021 22:51:16 +0100
Subject: [PATCH 1/7] feat(ThreadChannel): add owner and fetchOwner()
---
src/structures/ThreadChannel.js | 18 ++++++++++++++++++
typings/index.d.ts | 2 ++
2 files changed, 20 insertions(+)
diff --git a/src/structures/ThreadChannel.js b/src/structures/ThreadChannel.js
index 8c411daed902..8752a8edd0df 100644
--- a/src/structures/ThreadChannel.js
+++ b/src/structures/ThreadChannel.js
@@ -188,6 +188,15 @@ class ThreadChannel extends Channel {
return this.members.cache.mapValues(member => member.guildMember);
}
+ /**
+ * The {@link ThreadMember} object of the owner of this thread
+ * @type {?ThreadMember}
+ * @readonly
+ */
+ get owner() {
+ return this.members.cache.get(this.ownerId);
+ }
+
/**
* The time at which this thread's archive status was last changed
* If the thread was never archived or unarchived, this is the time at which the thread was created
@@ -234,6 +243,15 @@ class ThreadChannel extends Channel {
return this.parent?.permissionsFor(memberOrRole) ?? null;
}
+ /**
+ * Fetches the owner of this thread
+ * @param {FetchOwnerOptions} [options] The options for fetching the member
+ * @returns {Promise}
+ */
+ fetchOwner(options) {
+ return this.guild.members.fetch({ ...options, user: this.ownerId });
+ }
+
/**
* The options used to edit a thread channel
* @typedef {Object} ThreadEditData
diff --git a/typings/index.d.ts b/typings/index.d.ts
index bf5b8b9a9493..7a2a7456cc85 100644
--- a/typings/index.d.ts
+++ b/typings/index.d.ts
@@ -1688,6 +1688,7 @@ export class ThreadChannel extends TextBasedChannel(Channel) {
public members: ThreadMemberManager;
public name: string;
public ownerId: Snowflake | null;
+ public readonly owner: ThreadMember | null;
public readonly parent: TextChannel | NewsChannel | null;
public parentId: Snowflake | null;
public rateLimitPerUser: number | null;
@@ -1699,6 +1700,7 @@ export class ThreadChannel extends TextBasedChannel(Channel) {
public leave(): Promise;
public permissionsFor(memberOrRole: GuildMember | Role): Readonly;
public permissionsFor(memberOrRole: GuildMemberResolvable | RoleResolvable): Readonly | null;
+ public fetchOwner(options?: FetchOwnerOptions): Promise;
public setArchived(archived?: boolean, reason?: string): Promise;
public setAutoArchiveDuration(
autoArchiveDuration: ThreadAutoArchiveDuration,
From dcd38839c0e5dc20e90d7a776286c7c300e050ea Mon Sep 17 00:00:00 2001
From: Rodry <38259440+ImRodry@users.noreply.github.com>
Date: Wed, 28 Jul 2021 23:31:19 +0100
Subject: [PATCH 2/7] fix(ThreadChannel): remove owner and return ThreadMember
with fetchOwner
---
src/structures/ThreadChannel.js | 23 +++++++++++------------
typings/index.d.ts | 3 +--
2 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/src/structures/ThreadChannel.js b/src/structures/ThreadChannel.js
index 8752a8edd0df..6a87a0735a90 100644
--- a/src/structures/ThreadChannel.js
+++ b/src/structures/ThreadChannel.js
@@ -188,15 +188,6 @@ class ThreadChannel extends Channel {
return this.members.cache.mapValues(member => member.guildMember);
}
- /**
- * The {@link ThreadMember} object of the owner of this thread
- * @type {?ThreadMember}
- * @readonly
- */
- get owner() {
- return this.members.cache.get(this.ownerId);
- }
-
/**
* The time at which this thread's archive status was last changed
* If the thread was never archived or unarchived, this is the time at which the thread was created
@@ -246,10 +237,18 @@ class ThreadChannel extends Channel {
/**
* Fetches the owner of this thread
* @param {FetchOwnerOptions} [options] The options for fetching the member
- * @returns {Promise}
+ * @returns {Promise}
*/
- fetchOwner(options) {
- return this.guild.members.fetch({ ...options, user: this.ownerId });
+ async fetchOwner({ cache = true, force = false } = {}) {
+ if (!force) {
+ const existing = this.cache.get(this.ownerId);
+ if (existing) return existing;
+ }
+
+ // We cannot fetch a single thread member, as of this commit's date, Discord API throws with 405
+ const data = await this.client.api.channels(this.thread.id, 'thread-members').get();
+ const owner = data.find(member => member.user_id === this.ownerId);
+ return this._add(owner, cache);
}
/**
diff --git a/typings/index.d.ts b/typings/index.d.ts
index 7a2a7456cc85..67a41ed5ed5c 100644
--- a/typings/index.d.ts
+++ b/typings/index.d.ts
@@ -1688,7 +1688,6 @@ export class ThreadChannel extends TextBasedChannel(Channel) {
public members: ThreadMemberManager;
public name: string;
public ownerId: Snowflake | null;
- public readonly owner: ThreadMember | null;
public readonly parent: TextChannel | NewsChannel | null;
public parentId: Snowflake | null;
public rateLimitPerUser: number | null;
@@ -1700,7 +1699,7 @@ export class ThreadChannel extends TextBasedChannel(Channel) {
public leave(): Promise;
public permissionsFor(memberOrRole: GuildMember | Role): Readonly;
public permissionsFor(memberOrRole: GuildMemberResolvable | RoleResolvable): Readonly | null;
- public fetchOwner(options?: FetchOwnerOptions): Promise;
+ public fetchOwner(options?: FetchOwnerOptions): Promise;
public setArchived(archived?: boolean, reason?: string): Promise;
public setAutoArchiveDuration(
autoArchiveDuration: ThreadAutoArchiveDuration,
From 37989f775358fc0526281569d6866cab0365df21 Mon Sep 17 00:00:00 2001
From: Rodry <38259440+ImRodry@users.noreply.github.com>
Date: Thu, 29 Jul 2021 11:32:50 +0100
Subject: [PATCH 3/7] fix(ThreadChannel): apply suggestions from code review
Co-authored-by: SpaceEEC
---
src/structures/ThreadChannel.js | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/structures/ThreadChannel.js b/src/structures/ThreadChannel.js
index 6a87a0735a90..75d4bbc6178c 100644
--- a/src/structures/ThreadChannel.js
+++ b/src/structures/ThreadChannel.js
@@ -245,10 +245,9 @@ class ThreadChannel extends Channel {
if (existing) return existing;
}
- // We cannot fetch a single thread member, as of this commit's date, Discord API throws with 405
- const data = await this.client.api.channels(this.thread.id, 'thread-members').get();
- const owner = data.find(member => member.user_id === this.ownerId);
- return this._add(owner, cache);
+ // We cannot fetch a single thread member, as of this commit's date, Discord API responds with 405
+ const members = await this.members.fetch(cache);
+ return members.get(this.ownerId);
}
/**
From 88b894b619463806e2d52d9a0b22b95b9ee20815 Mon Sep 17 00:00:00 2001
From: Rodry <38259440+ImRodry@users.noreply.github.com>
Date: Thu, 29 Jul 2021 19:43:11 +0100
Subject: [PATCH 4/7] fix(ThreadChannel): correctly point to the manager
---
src/structures/ThreadChannel.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/structures/ThreadChannel.js b/src/structures/ThreadChannel.js
index 75d4bbc6178c..1fe59cea4711 100644
--- a/src/structures/ThreadChannel.js
+++ b/src/structures/ThreadChannel.js
@@ -241,7 +241,7 @@ class ThreadChannel extends Channel {
*/
async fetchOwner({ cache = true, force = false } = {}) {
if (!force) {
- const existing = this.cache.get(this.ownerId);
+ const existing = this.members.cache.get(this.ownerId);
if (existing) return existing;
}
From 948db050dafb67d6fdcb9e2a4dd76724ecbb4704 Mon Sep 17 00:00:00 2001
From: Rodry <38259440+ImRodry@users.noreply.github.com>
Date: Thu, 29 Jul 2021 22:50:07 +0100
Subject: [PATCH 5/7] docs(FetchOwnerOptions): update desc to mention threads
---
src/structures/Guild.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/structures/Guild.js b/src/structures/Guild.js
index ec927b435a58..f1d45041dc5a 100644
--- a/src/structures/Guild.js
+++ b/src/structures/Guild.js
@@ -458,7 +458,7 @@ class Guild extends AnonymousGuild {
}
/**
- * Options used to fetch the owner of guild.
+ * Options used to fetch the owner of a guild or a thread.
* @typedef {Object} FetchOwnerOptions
* @property {boolean} [cache=true] Whether or not to cache the fetched member
* @property {boolean} [force=false] Whether to skip the cache check and request the API
From 881839f94efb2f26f1f7946e78fa34b440ae1179 Mon Sep 17 00:00:00 2001
From: Rodry <38259440+ImRodry@users.noreply.github.com>
Date: Thu, 29 Jul 2021 23:22:07 +0100
Subject: [PATCH 6/7] fix(ThreadChannel): fetchOwner can return null
---
src/structures/ThreadChannel.js | 2 +-
typings/index.d.ts | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/structures/ThreadChannel.js b/src/structures/ThreadChannel.js
index 1fe59cea4711..8d01baf4ff68 100644
--- a/src/structures/ThreadChannel.js
+++ b/src/structures/ThreadChannel.js
@@ -247,7 +247,7 @@ class ThreadChannel extends Channel {
// We cannot fetch a single thread member, as of this commit's date, Discord API responds with 405
const members = await this.members.fetch(cache);
- return members.get(this.ownerId);
+ return members.get(this.ownerId) ?? null;
}
/**
diff --git a/typings/index.d.ts b/typings/index.d.ts
index 67a41ed5ed5c..54dc1dedf44f 100644
--- a/typings/index.d.ts
+++ b/typings/index.d.ts
@@ -1699,7 +1699,7 @@ export class ThreadChannel extends TextBasedChannel(Channel) {
public leave(): Promise;
public permissionsFor(memberOrRole: GuildMember | Role): Readonly;
public permissionsFor(memberOrRole: GuildMemberResolvable | RoleResolvable): Readonly | null;
- public fetchOwner(options?: FetchOwnerOptions): Promise;
+ public fetchOwner(options?: FetchOwnerOptions): Promise;
public setArchived(archived?: boolean, reason?: string): Promise;
public setAutoArchiveDuration(
autoArchiveDuration: ThreadAutoArchiveDuration,
From 6405a1d2460a78bb306cc0a88d75863bcffe19d6 Mon Sep 17 00:00:00 2001
From: Rodry <38259440+ImRodry@users.noreply.github.com>
Date: Fri, 30 Jul 2021 00:31:03 +0100
Subject: [PATCH 7/7] docs(ThreadChannel): owner is nullable
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
---
src/structures/ThreadChannel.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/structures/ThreadChannel.js b/src/structures/ThreadChannel.js
index 8d01baf4ff68..ac91157f5c9e 100644
--- a/src/structures/ThreadChannel.js
+++ b/src/structures/ThreadChannel.js
@@ -237,7 +237,7 @@ class ThreadChannel extends Channel {
/**
* Fetches the owner of this thread
* @param {FetchOwnerOptions} [options] The options for fetching the member
- * @returns {Promise}
+ * @returns {Promise}
*/
async fetchOwner({ cache = true, force = false } = {}) {
if (!force) {