refactor(ThreadManager)!: match parent ID when fetching a single thread (#10557)

BREAKING CHANGE: `ThreadManager#fetch` now throws when the provided thread ID doesn't belong to the current channel
This commit is contained in:
Naiyar
2024-11-05 16:30:44 +05:30
committed by GitHub
parent 939e3644e1
commit 1184b38d3e
3 changed files with 10 additions and 2 deletions

View File

@@ -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',

View File

@@ -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.',

View File

@@ -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);
}