Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/discord.js/src/errors/ErrorCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
* @property {'MessageThreadParent'} MessageThreadParent
* @property {'MessageExistingThread'} MessageExistingThread
* @property {'ThreadInvitableType'} ThreadInvitableType
* @property {'NotAThreadOfParent'} NotAThreadOfParent

* @property {'WebhookMessage'} WebhookMessage
* @property {'WebhookTokenUnavailable'} WebhookTokenUnavailable
Expand Down Expand Up @@ -201,6 +202,7 @@ const keys = [
'MessageThreadParent',
'MessageExistingThread',
'ThreadInvitableType',
'NotAThreadOfParent',

'WebhookMessage',
'WebhookTokenUnavailable',
Expand Down
1 change: 1 addition & 0 deletions packages/discord.js/src/errors/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
9 changes: 7 additions & 2 deletions packages/discord.js/src/managers/ThreadManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down