Package net.dv8tion.jda.api.entities
Class MessageReference
- java.lang.Object
-
- net.dv8tion.jda.api.entities.MessageReference
-
public class MessageReference extends java.lang.Object
An object representing a reference in a Discord message.- See Also:
Message.getMessageReference()
-
-
Constructor Summary
Constructors Constructor Description MessageReference(long messageId, long channelId, long guildId, Message referencedMessage, JDA api)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MessageChannel
getChannel()
The channel from which this message originates.java.lang.String
getChannelId()
Returns the channel id for this reference, or 0 if no channel id was provided.long
getChannelIdLong()
Returns the channel id for this reference, or 0 if no channel id was provided.Guild
getGuild()
The guild for this reference.java.lang.String
getGuildId()
Returns the guild id for this reference, or 0 if no guild id was provided.long
getGuildIdLong()
Returns the guild id for this reference, or 0 if no guild id was provided.JDA
getJDA()
Returns the JDA instance related to this message reference.Message
getMessage()
The resolved message, if available.java.lang.String
getMessageId()
Returns the message id for this reference, or 0 if no message id was provided.long
getMessageIdLong()
Returns the message id for this reference, or 0 if no message id was provided.RestAction<Message>
resolve()
Retrieves the referenced message for this message.RestAction<Message>
resolve(boolean update)
Retrieves the referenced message for this message.
-
-
-
Method Detail
-
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:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theTextChannel
.UNKNOWN_MESSAGE
The message has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Returns:
RestAction
- Type:Message
- Throws:
InsufficientPermissionException
- If this reference refers to aTextChannel
and the logged in account does not havejava.lang.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:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theTextChannel
.UNKNOWN_MESSAGE
The message has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Parameters:
update
- Whether to update the already stored message- Returns:
RestAction
- Type:Message
- Throws:
InsufficientPermissionException
- If this reference refers to aTextChannel
and the logged in account does not havejava.lang.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 aINLINE_REPLY
reference. This can be null even if the type isINLINE_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:
resolve()
-
getChannel
@Nullable public MessageChannel 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:
getChannelId()
-
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:
getGuildId()
-
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 java.lang.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 java.lang.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 java.lang.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
-
-