Skip to content

Commit eceaa85

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 d0dc864 commit eceaa85

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
@@ -5,7 +5,7 @@ const { ChannelFlags, ChannelType, PermissionFlagsBits, Routes } = require('disc
55
const { BaseChannel } = require('./BaseChannel');
66
const getThreadOnlyChannel = lazy(() => require('./ThreadOnlyChannel'));
77
const TextBasedChannel = require('./interfaces/TextBasedChannel');
8-
const { DiscordjsError, DiscordjsRangeError, ErrorCodes } = require('../errors');
8+
const { DiscordjsRangeError, ErrorCodes } = require('../errors');
99
const GuildMessageManager = require('../managers/GuildMessageManager');
1010
const ThreadMemberManager = require('../managers/ThreadMemberManager');
1111
const ChannelFlagsBitField = require('../util/ChannelFlagsBitField');
@@ -31,6 +31,12 @@ class ThreadChannel extends BaseChannel {
3131
*/
3232
this.guildId = guild?.id ?? data.guild_id;
3333

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

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

124-
if ('owner_id' in data) {
125-
/**
126-
* The id of the member who created this thread
127-
* @type {?Snowflake}
128-
*/
129-
this.ownerId = data.owner_id;
130-
} else {
131-
this.ownerId ??= null;
132-
}
133-
134130
if ('last_message_id' in data) {
135131
/**
136132
* The last message id sent in this thread, if one was sent
@@ -300,10 +296,6 @@ class ThreadChannel extends BaseChannel {
300296
* @returns {Promise<ThreadMember>}
301297
*/
302298
async fetchOwner(options) {
303-
if (!this.ownerId) {
304-
throw new DiscordjsError(ErrorCodes.FetchOwnerId, 'thread');
305-
}
306-
307299
const member = await this.members._fetchSingle({ ...options, member: this.ownerId });
308300
return member;
309301
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3376,7 +3376,7 @@ export class ThreadChannel<ThreadOnly extends boolean = boolean> extends BaseCha
33763376
public totalMessageSent: number | null;
33773377
public members: ThreadMemberManager;
33783378
public name: string;
3379-
public ownerId: Snowflake | null;
3379+
public ownerId: Snowflake;
33803380
public get parent(): If<ThreadOnly, ForumChannel | MediaChannel, TextChannel | AnnouncementChannel> | null;
33813381
public parentId: Snowflake | null;
33823382
public rateLimitPerUser: number | null;

0 commit comments

Comments
 (0)