mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
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>
This commit is contained in:
@@ -354,15 +354,15 @@ class Message extends Base {
|
|||||||
* Reference data sent in a message that contains ids identifying the referenced message.
|
* Reference data sent in a message that contains ids identifying the referenced message.
|
||||||
* This can be present in the following types of message:
|
* This can be present in the following types of message:
|
||||||
* * Crossposted messages (`MessageFlags.Crossposted`)
|
* * Crossposted messages (`MessageFlags.Crossposted`)
|
||||||
* * {@link MessageType.ChannelFollowAdd}
|
|
||||||
* * {@link MessageType.ChannelPinnedMessage}
|
* * {@link MessageType.ChannelPinnedMessage}
|
||||||
|
* * {@link MessageType.ChannelFollowAdd}
|
||||||
* * {@link MessageType.Reply}
|
* * {@link MessageType.Reply}
|
||||||
* * {@link MessageType.ThreadStarterMessage}
|
* * {@link MessageType.ThreadStarterMessage}
|
||||||
* @see {@link https://discord.com/developers/docs/resources/channel#message-types}
|
* @see {@link https://discord.com/developers/docs/resources/channel#message-types}
|
||||||
* @typedef {Object} MessageReference
|
* @typedef {Object} MessageReference
|
||||||
* @property {Snowflake} channelId The channel's id the message was referenced
|
* @property {Snowflake} channelId The channel id that was referenced
|
||||||
* @property {?Snowflake} guildId The guild's id the message was referenced
|
* @property {Snowflake|undefined} guildId The guild id that was referenced
|
||||||
* @property {?Snowflake} messageId The message's id that was referenced
|
* @property {Snowflake|undefined} messageId The message id that was referenced
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ('message_reference' in data) {
|
if ('message_reference' in data) {
|
||||||
@@ -708,6 +708,7 @@ class Message extends Base {
|
|||||||
async fetchReference() {
|
async fetchReference() {
|
||||||
if (!this.reference) throw new DiscordjsError(ErrorCodes.MessageReferenceMissing);
|
if (!this.reference) throw new DiscordjsError(ErrorCodes.MessageReferenceMissing);
|
||||||
const { channelId, messageId } = this.reference;
|
const { channelId, messageId } = this.reference;
|
||||||
|
if (!messageId) throw new DiscordjsError(ErrorCodes.MessageReferenceMissing);
|
||||||
const channel = this.client.channels.resolve(channelId);
|
const channel = this.client.channels.resolve(channelId);
|
||||||
if (!channel) throw new DiscordjsError(ErrorCodes.GuildChannelResolve);
|
if (!channel) throw new DiscordjsError(ErrorCodes.GuildChannelResolve);
|
||||||
const message = await channel.messages.fetch(messageId);
|
const message = await channel.messages.fetch(messageId);
|
||||||
|
|||||||
Reference in New Issue
Block a user