mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 12:33:30 +01:00
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>
This commit is contained in:
@@ -6,7 +6,7 @@ const { RESTJSONErrorCodes, ChannelFlags, ChannelType, PermissionFlagsBits, Rout
|
|||||||
const { BaseChannel } = require('./BaseChannel');
|
const { BaseChannel } = require('./BaseChannel');
|
||||||
const getThreadOnlyChannel = lazy(() => require('./ThreadOnlyChannel'));
|
const getThreadOnlyChannel = lazy(() => require('./ThreadOnlyChannel'));
|
||||||
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
||||||
const { DiscordjsError, DiscordjsRangeError, ErrorCodes } = require('../errors');
|
const { DiscordjsRangeError, ErrorCodes } = require('../errors');
|
||||||
const GuildMessageManager = require('../managers/GuildMessageManager');
|
const GuildMessageManager = require('../managers/GuildMessageManager');
|
||||||
const ThreadMemberManager = require('../managers/ThreadMemberManager');
|
const ThreadMemberManager = require('../managers/ThreadMemberManager');
|
||||||
const ChannelFlagsBitField = require('../util/ChannelFlagsBitField');
|
const ChannelFlagsBitField = require('../util/ChannelFlagsBitField');
|
||||||
@@ -32,6 +32,12 @@ class ThreadChannel extends BaseChannel {
|
|||||||
*/
|
*/
|
||||||
this.guildId = guild?.id ?? data.guild_id;
|
this.guildId = guild?.id ?? data.guild_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The id of the member who created this thread
|
||||||
|
* @type {Snowflake}
|
||||||
|
*/
|
||||||
|
this.ownerId = data.owner_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A manager of the messages sent to this thread
|
* A manager of the messages sent to this thread
|
||||||
* @type {GuildMessageManager}
|
* @type {GuildMessageManager}
|
||||||
@@ -122,16 +128,6 @@ class ThreadChannel extends BaseChannel {
|
|||||||
|
|
||||||
this._createdTimestamp ??= this.type === ChannelType.PrivateThread ? super.createdTimestamp : null;
|
this._createdTimestamp ??= this.type === ChannelType.PrivateThread ? super.createdTimestamp : null;
|
||||||
|
|
||||||
if ('owner_id' in data) {
|
|
||||||
/**
|
|
||||||
* The id of the member who created this thread
|
|
||||||
* @type {?Snowflake}
|
|
||||||
*/
|
|
||||||
this.ownerId = data.owner_id;
|
|
||||||
} else {
|
|
||||||
this.ownerId ??= null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('last_message_id' in data) {
|
if ('last_message_id' in data) {
|
||||||
/**
|
/**
|
||||||
* The last message id sent in this thread, if one was sent
|
* The last message id sent in this thread, if one was sent
|
||||||
@@ -301,10 +297,6 @@ class ThreadChannel extends BaseChannel {
|
|||||||
* @returns {Promise<?ThreadMember>}
|
* @returns {Promise<?ThreadMember>}
|
||||||
*/
|
*/
|
||||||
async fetchOwner(options) {
|
async fetchOwner(options) {
|
||||||
if (!this.ownerId) {
|
|
||||||
throw new DiscordjsError(ErrorCodes.FetchOwnerId, 'thread');
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Remove that catch in the next major version
|
// TODO: Remove that catch in the next major version
|
||||||
const member = await this.members._fetchSingle({ ...options, member: this.ownerId }).catch(error => {
|
const member = await this.members._fetchSingle({ ...options, member: this.ownerId }).catch(error => {
|
||||||
if (error instanceof DiscordAPIError && error.code === RESTJSONErrorCodes.UnknownMember) {
|
if (error instanceof DiscordAPIError && error.code === RESTJSONErrorCodes.UnknownMember) {
|
||||||
|
|||||||
2
packages/discord.js/typings/index.d.ts
vendored
2
packages/discord.js/typings/index.d.ts
vendored
@@ -3384,7 +3384,7 @@ export class ThreadChannel<ThreadOnly extends boolean = boolean> extends BaseCha
|
|||||||
public totalMessageSent: number | null;
|
public totalMessageSent: number | null;
|
||||||
public members: ThreadMemberManager;
|
public members: ThreadMemberManager;
|
||||||
public name: string;
|
public name: string;
|
||||||
public ownerId: Snowflake | null;
|
public ownerId: Snowflake;
|
||||||
public get parent(): If<ThreadOnly, ForumChannel | MediaChannel, TextChannel | NewsChannel> | null;
|
public get parent(): If<ThreadOnly, ForumChannel | MediaChannel, TextChannel | NewsChannel> | null;
|
||||||
public parentId: Snowflake | null;
|
public parentId: Snowflake | null;
|
||||||
public rateLimitPerUser: number | null;
|
public rateLimitPerUser: number | null;
|
||||||
|
|||||||
Reference in New Issue
Block a user