Skip to content

Commit 7678f11

Browse files
fix(ThreadChannel): Make ownerId always present (#10618)
fix: thread owner id is always present Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 4cca33d commit 7678f11

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

packages/discord.js/src/structures/ThreadChannel.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { RESTJSONErrorCodes, ChannelFlags, ChannelType, PermissionFlagsBits, Rout
66
const { BaseChannel } = require('./BaseChannel');
77
const getThreadOnlyChannel = lazy(() => require('./ThreadOnlyChannel'));
88
const TextBasedChannel = require('./interfaces/TextBasedChannel');
9-
const { DiscordjsError, DiscordjsRangeError, ErrorCodes } = require('../errors');
9+
const { DiscordjsRangeError, ErrorCodes } = require('../errors');
1010
const GuildMessageManager = require('../managers/GuildMessageManager');
1111
const ThreadMemberManager = require('../managers/ThreadMemberManager');
1212
const ChannelFlagsBitField = require('../util/ChannelFlagsBitField');
@@ -32,6 +32,12 @@ class ThreadChannel extends BaseChannel {
3232
*/
3333
this.guildId = guild?.id ?? data.guild_id;
3434

35+
/**
36+
* The id of the member who created this thread
37+
* @type {Snowflake}
38+
*/
39+
this.ownerId = data.owner_id;
40+
3541
/**
3642
* A manager of the messages sent to this thread
3743
* @type {GuildMessageManager}
@@ -122,16 +128,6 @@ class ThreadChannel extends BaseChannel {
122128

123129
this._createdTimestamp ??= this.type === ChannelType.PrivateThread ? super.createdTimestamp : null;
124130

125-
if ('owner_id' in data) {
126-
/**
127-
* The id of the member who created this thread
128-
* @type {?Snowflake}
129-
*/
130-
this.ownerId = data.owner_id;
131-
} else {
132-
this.ownerId ??= null;
133-
}
134-
135131
if ('last_message_id' in data) {
136132
/**
137133
* The last message id sent in this thread, if one was sent
@@ -301,10 +297,6 @@ class ThreadChannel extends BaseChannel {
301297
* @returns {Promise<?ThreadMember>}
302298
*/
303299
async fetchOwner(options) {
304-
if (!this.ownerId) {
305-
throw new DiscordjsError(ErrorCodes.FetchOwnerId, 'thread');
306-
}
307-
308300
// TODO: Remove that catch in the next major version
309301
const member = await this.members._fetchSingle({ ...options, member: this.ownerId }).catch(error => {
310302
if (error instanceof DiscordAPIError && error.code === RESTJSONErrorCodes.UnknownMember) {

packages/discord.js/typings/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3384,7 +3384,7 @@ export class ThreadChannel<ThreadOnly extends boolean = boolean> extends BaseCha
33843384
public totalMessageSent: number | null;
33853385
public members: ThreadMemberManager;
33863386
public name: string;
3387-
public ownerId: Snowflake | null;
3387+
public ownerId: Snowflake;
33883388
public get parent(): If<ThreadOnly, ForumChannel | MediaChannel, TextChannel | NewsChannel> | null;
33893389
public parentId: Snowflake | null;
33903390
public rateLimitPerUser: number | null;

0 commit comments

Comments
 (0)