mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
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:
@@ -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',
|
||||
|
||||
@@ -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.',
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user