From 98177aa38d3d6516d4c5354d6c7edea925dc881d Mon Sep 17 00:00:00 2001 From: Ryan Munro Date: Fri, 25 Mar 2022 06:58:29 +1100 Subject: [PATCH] fix(guild): throw if ownerId falsey (#7575) --- packages/discord.js/src/errors/Messages.js | 1 + packages/discord.js/src/structures/Guild.js | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/discord.js/src/errors/Messages.js b/packages/discord.js/src/errors/Messages.js index 0660d3cccc87..0d50cbed0692 100644 --- a/packages/discord.js/src/errors/Messages.js +++ b/packages/discord.js/src/errors/Messages.js @@ -90,6 +90,7 @@ const Messages = { CHANNEL_NOT_CACHED: 'Could not find the channel where this message came from in the cache!', STAGE_CHANNEL_RESOLVE: 'Could not resolve channel to a stage channel.', GUILD_SCHEDULED_EVENT_RESOLVE: 'Could not resolve the guild scheduled event.', + FETCH_OWNER_ID: "Couldn't resolve the guild ownerId to fetch the member.", INVALID_TYPE: (name, expected, an = false) => `Supplied ${name} is not a${an ? 'n' : ''} ${expected}.`, INVALID_ELEMENT: (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 4474d4d71bb8..42d7d0391d73 100644 --- a/packages/discord.js/src/structures/Guild.js +++ b/packages/discord.js/src/structures/Guild.js @@ -451,8 +451,12 @@ class Guild extends AnonymousGuild { * @param {BaseFetchOptions} [options] The options for fetching the member * @returns {Promise} */ - fetchOwner(options) { - return this.members.fetch({ ...options, user: this.ownerId }); + async fetchOwner(options) { + if (!this.ownerId) { + throw new Error('FETCH_OWNER_ID'); + } + const member = await this.members.fetch({ ...options, user: this.ownerId }); + return member; } /**