Class MessageReference

java.lang.Object
net.dv8tion.jda.api.entities.MessageReference

public class MessageReference extends Object
An object representing a reference in a Discord message.
See Also:
  • Constructor Details

    • MessageReference

      public MessageReference(long messageId, long channelId, long guildId, @Nullable Message referencedMessage, JDA api)
  • Method Details

    • resolve

      @Nonnull public RestAction<Message> resolve()
      Retrieves the referenced message for this message.
      If the message already exists, it will be returned immediately.

      The following ErrorResponses are possible:

      Returns:
      RestAction - Type: Message
      Throws:
      InsufficientPermissionException - If this reference refers to a GuildChannel and the logged in account does not have
      IllegalStateException - If this message reference does not have a channel
    • resolve

      @Nonnull public RestAction<Message> resolve(boolean update)
      Retrieves the referenced message for this message.
      If the message already exists, it will be returned immediately.

      The following ErrorResponses are possible:

      Parameters:
      update - Whether to update the already stored message
      Returns:
      RestAction - Type: Message
      Throws:
      InsufficientPermissionException - If this reference refers to a GuildChannel and the logged in account does not have
      IllegalStateException - If this message reference does not have a channel
    • getMessage

      @Nullable public Message getMessage()
      The resolved message, if available.

      This will have different meaning depending on the type of message. Usually, this is a INLINE_REPLY reference. This can be null even if the type is INLINE_REPLY, when the message it references doesn't exist or discord wasn't able to resolve it in time.

      Returns:
      The referenced message, or null if this is not available
      See Also:
    • getChannel

      @Nullable public MessageChannelUnion getChannel()
      The channel from which this message originates.
      Messages from other guilds can be referenced, in which case JDA may not have the channel cached.
      Returns:
      The origin channel for this message reference, or null if this is not available
      See Also:
    • getGuild

      @Nullable public Guild getGuild()
      The guild for this reference.
      This will be null if the message did not come from a guild, the guild was not provided, or JDA did not have the guild cached
      Returns:
      The guild, or null if this is not available
      See Also:
    • getMessageIdLong

      public long getMessageIdLong()
      Returns the message id for this reference, or 0 if no message id was provided.
      Returns:
      The message id, or 0.
    • getChannelIdLong

      public long getChannelIdLong()
      Returns the channel id for this reference, or 0 if no channel id was provided.
      Returns:
      The channel id, or 0.
    • getGuildIdLong

      public long getGuildIdLong()
      Returns the guild id for this reference, or 0 if no guild id was provided.
      Returns:
      The guild id, or 0.
    • getMessageId

      @Nonnull public String getMessageId()
      Returns the message id for this reference, or 0 if no message id was provided.
      Returns:
      The message id, or 0.
    • getChannelId

      @Nonnull public String getChannelId()
      Returns the channel id for this reference, or 0 if no channel id was provided.
      Returns:
      The channel id, or 0.
    • getGuildId

      @Nonnull public String getGuildId()
      Returns the guild id for this reference, or 0 if no guild id was provided.
      Returns:
      The guild id, or 0.
    • getJDA

      @Nonnull public JDA getJDA()
      Returns the JDA instance related to this message reference.
      Returns:
      The corresponding JDA instance