Skip to content

fix: Throw error on no message id for Message#fetchReference() #10295

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

Merged
merged 5 commits into from
May 24, 2024
Merged
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
9 changes: 5 additions & 4 deletions packages/discord.js/src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,15 @@ class Message extends Base {
* Reference data sent in a message that contains ids identifying the referenced message.
* This can be present in the following types of message:
* * Crossposted messages (`MessageFlags.Crossposted`)
* * {@link MessageType.ChannelFollowAdd}
* * {@link MessageType.ChannelPinnedMessage}
* * {@link MessageType.ChannelFollowAdd}
* * {@link MessageType.Reply}
* * {@link MessageType.ThreadStarterMessage}
* @see {@link https://discord.com/developers/docs/resources/channel#message-types}
* @typedef {Object} MessageReference
* @property {Snowflake} channelId The channel's id the message was referenced
* @property {?Snowflake} guildId The guild's id the message was referenced
* @property {?Snowflake} messageId The message's id that was referenced
* @property {Snowflake} channelId The channel id that was referenced
* @property {Snowflake|undefined} guildId The guild id that was referenced
* @property {Snowflake|undefined} messageId The message id that was referenced
*/

if ('message_reference' in data) {
Expand Down Expand Up @@ -708,6 +708,7 @@ class Message extends Base {
async fetchReference() {
if (!this.reference) throw new DiscordjsError(ErrorCodes.MessageReferenceMissing);
const { channelId, messageId } = this.reference;
if (!messageId) throw new DiscordjsError(ErrorCodes.MessageReferenceMissing);
const channel = this.client.channels.resolve(channelId);
if (!channel) throw new DiscordjsError(ErrorCodes.GuildChannelResolve);
const message = await channel.messages.fetch(messageId);
Expand Down
Loading