diff --git a/packages/discord.js/src/errors/Messages.js b/packages/discord.js/src/errors/Messages.js index b3c0514dfa61d..c7927328ca232 100644 --- a/packages/discord.js/src/errors/Messages.js +++ b/packages/discord.js/src/errors/Messages.js @@ -95,7 +95,7 @@ const Messages = { [DjsErrorCodes.ChannelNotCached]: 'Could not find the channel where this message came from in the cache!', [DjsErrorCodes.StageChannelResolve]: 'Could not resolve channel to a stage channel.', [DjsErrorCodes.GuildScheduledEventResolve]: 'Could not resolve the guild scheduled event.', - [DjsErrorCodes.FetchOwnerId]: "Couldn't resolve the guild ownerId to fetch the member.", + [DjsErrorCodes.FetchOwnerId]: type => `Couldn't resolve the ${type} ownerId to fetch the ${type} member.`, [DjsErrorCodes.InvalidType]: (name, expected, an = false) => `Supplied ${name} is not a${an ? 'n' : ''} ${expected}.`, [DjsErrorCodes.InvalidElement]: (type, name, elem) => `Supplied ${type} ${name} includes an invalid element: ${elem}`, diff --git a/packages/discord.js/src/structures/Guild.js b/packages/discord.js/src/structures/Guild.js index 9f7320762f33d..831dae326dc37 100644 --- a/packages/discord.js/src/structures/Guild.js +++ b/packages/discord.js/src/structures/Guild.js @@ -495,7 +495,7 @@ class Guild extends AnonymousGuild { */ async fetchOwner(options) { if (!this.ownerId) { - throw new DiscordjsError(ErrorCodes.FetchOwnerId); + throw new DiscordjsError(ErrorCodes.FetchOwnerId, 'guild'); } const member = await this.members.fetch({ ...options, user: this.ownerId }); return member; diff --git a/packages/discord.js/src/structures/ThreadChannel.js b/packages/discord.js/src/structures/ThreadChannel.js index fdb5fdf82fe13..30a6cc9a48c4c 100644 --- a/packages/discord.js/src/structures/ThreadChannel.js +++ b/packages/discord.js/src/structures/ThreadChannel.js @@ -5,7 +5,7 @@ const { ChannelType, PermissionFlagsBits, Routes, ChannelFlags } = require('disc const { BaseChannel } = require('./BaseChannel'); const getThreadOnlyChannel = lazy(() => require('./ThreadOnlyChannel')); const TextBasedChannel = require('./interfaces/TextBasedChannel'); -const { DiscordjsRangeError, ErrorCodes } = require('../errors'); +const { DiscordjsError, DiscordjsRangeError, ErrorCodes } = require('../errors'); const GuildMessageManager = require('../managers/GuildMessageManager'); const ThreadMemberManager = require('../managers/ThreadMemberManager'); const ChannelFlagsBitField = require('../util/ChannelFlagsBitField'); @@ -291,17 +291,15 @@ class ThreadChannel extends BaseChannel { * Fetches the owner of this thread. If the thread member object isn't needed, * use {@link ThreadChannel#ownerId} instead. * @param {BaseFetchOptions} [options] The options for fetching the member - * @returns {Promise} + * @returns {Promise} */ - async fetchOwner({ cache = true, force = false } = {}) { - if (!force) { - const existing = this.members.cache.get(this.ownerId); - if (existing) return existing; + async fetchOwner(options) { + if (!this.ownerId) { + throw new DiscordjsError(ErrorCodes.FetchOwnerId, 'thread'); } - // We cannot fetch a single thread member, as of this commit's date, Discord API responds with 405 - const members = await this.members.fetch({ cache }); - return members.get(this.ownerId) ?? null; + const member = await this.members.fetch({ ...options, member: this.ownerId }); + return member; } /** diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 6eb49bb2bf428..462076205037b 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -3197,7 +3197,7 @@ export class ThreadChannel extends BaseCha memberOrRole: GuildMemberResolvable | RoleResolvable, checkAdmin?: boolean, ): Readonly | null; - public fetchOwner(options?: BaseFetchOptions): Promise; + public fetchOwner(options?: BaseFetchOptions): Promise; public fetchStarterMessage(options?: BaseFetchOptions): Promise | null>; public setArchived(archived?: boolean, reason?: string): Promise; public setAutoArchiveDuration(