diff --git a/packages/discord.js/src/errors/ErrorCodes.js b/packages/discord.js/src/errors/ErrorCodes.js index f23b3232b442..b160068e7669 100644 --- a/packages/discord.js/src/errors/ErrorCodes.js +++ b/packages/discord.js/src/errors/ErrorCodes.js @@ -73,6 +73,7 @@ * @property {'MessageThreadParent'} MessageThreadParent * @property {'MessageExistingThread'} MessageExistingThread * @property {'ThreadInvitableType'} ThreadInvitableType + * @property {'NotAThreadOfParent'} NotAThreadOfParent * @property {'WebhookMessage'} WebhookMessage * @property {'WebhookTokenUnavailable'} WebhookTokenUnavailable @@ -201,6 +202,7 @@ const keys = [ 'MessageThreadParent', 'MessageExistingThread', 'ThreadInvitableType', + 'NotAThreadOfParent', 'WebhookMessage', 'WebhookTokenUnavailable', diff --git a/packages/discord.js/src/errors/Messages.js b/packages/discord.js/src/errors/Messages.js index 2ee1ab3405e4..133c4d0cee50 100644 --- a/packages/discord.js/src/errors/Messages.js +++ b/packages/discord.js/src/errors/Messages.js @@ -78,6 +78,7 @@ const Messages = { [DjsErrorCodes.MessageThreadParent]: 'The message was not sent in a guild text or announcement channel', [DjsErrorCodes.MessageExistingThread]: 'The message already has a thread', [DjsErrorCodes.ThreadInvitableType]: type => `Invitable cannot be edited on ${type}`, + [DjsErrorCodes.NotAThreadOfParent]: 'Provided ThreadChannelResolvable is not a thread of the parent channel.', [DjsErrorCodes.WebhookMessage]: 'The message was not sent by a webhook.', [DjsErrorCodes.WebhookTokenUnavailable]: 'This action requires a webhook token, but none is available.', diff --git a/packages/discord.js/src/managers/ThreadManager.js b/packages/discord.js/src/managers/ThreadManager.js index a8bf2a67e83c..afb75a1e0b7a 100644 --- a/packages/discord.js/src/managers/ThreadManager.js +++ b/packages/discord.js/src/managers/ThreadManager.js @@ -83,10 +83,15 @@ class ThreadManager extends CachedManager { * .then(channel => console.log(channel.name)) * .catch(console.error); */ - fetch(options, { cache, force } = {}) { + async fetch(options, { cache, force } = {}) { if (!options) return this.fetchActive(cache); const channel = this.client.channels.resolveId(options); - if (channel) return this.client.channels.fetch(channel, { cache, force }); + if (channel) { + const threadChannel = await this.client.channels.fetch(channel, { cache, force }); + if (threadChannel.parentId !== this.channel.id) throw new DiscordjsTypeError(ErrorCodes.NotAThreadOfParent); + return threadChannel; + } + if (options.archived) { return this.fetchArchived(options.archived, cache); }