Skip to content

Commit 638b896

Browse files
fix: Throw error on no message id for Message#fetchReference() (#10295)
* docs(MessageReference): ? is nullable, not `undefined` * docs(MessageReference): sort by message type * fix(Message): add throw * docs(MessageReference): fix English --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 27d0659 commit 638b896

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/discord.js/src/structures/Message.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,15 +354,15 @@ class Message extends Base {
354354
* Reference data sent in a message that contains ids identifying the referenced message.
355355
* This can be present in the following types of message:
356356
* * Crossposted messages (`MessageFlags.Crossposted`)
357-
* * {@link MessageType.ChannelFollowAdd}
358357
* * {@link MessageType.ChannelPinnedMessage}
358+
* * {@link MessageType.ChannelFollowAdd}
359359
* * {@link MessageType.Reply}
360360
* * {@link MessageType.ThreadStarterMessage}
361361
* @see {@link https://discord.com/developers/docs/resources/channel#message-types}
362362
* @typedef {Object} MessageReference
363-
* @property {Snowflake} channelId The channel's id the message was referenced
364-
* @property {?Snowflake} guildId The guild's id the message was referenced
365-
* @property {?Snowflake} messageId The message's id that was referenced
363+
* @property {Snowflake} channelId The channel id that was referenced
364+
* @property {Snowflake|undefined} guildId The guild id that was referenced
365+
* @property {Snowflake|undefined} messageId The message id that was referenced
366366
*/
367367

368368
if ('message_reference' in data) {
@@ -708,6 +708,7 @@ class Message extends Base {
708708
async fetchReference() {
709709
if (!this.reference) throw new DiscordjsError(ErrorCodes.MessageReferenceMissing);
710710
const { channelId, messageId } = this.reference;
711+
if (!messageId) throw new DiscordjsError(ErrorCodes.MessageReferenceMissing);
711712
const channel = this.client.channels.resolve(channelId);
712713
if (!channel) throw new DiscordjsError(ErrorCodes.GuildChannelResolve);
713714
const message = await channel.messages.fetch(messageId);

0 commit comments

Comments
 (0)