Package net.dv8tion.jda.api.entities
Class MessageReaction
- java.lang.Object
-
- net.dv8tion.jda.api.entities.MessageReaction
-
public class MessageReaction extends java.lang.Object
An object representing a single MessageReaction from Discord. This is an immutable object and is not updated by method calls or changes in Discord. A new snapshot instance built from Discord is needed to see changes.- Since:
- 3.0
- See Also:
Message.getReactions()
,Message.getReactionByUnicode(String)
,Message.getReactionById(long)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MessageReaction.ReactionEmote
Represents an Emoji/Emote of a MessageReaction
This is used to wrap both emojis and emotes
-
Constructor Summary
Constructors Constructor Description MessageReaction(MessageChannel channel, MessageReaction.ReactionEmote emote, long messageId, boolean self, int count)
Creates a new MessageReaction instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RestAction<java.lang.Void>
clearReactions()
Removes this entire reaction from the message.boolean
equals(java.lang.Object obj)
MessageChannel
getChannel()
TheMessageChannel
this Reaction was used in.ChannelType
getChannelType()
TheChannelType
this Reaction was used in.int
getCount()
The amount of users that already reacted with this Reaction
This is not updated, it is afinal int
per Reaction instanceGuild
getGuild()
JDA
getJDA()
The JDA instance of this Reactionjava.lang.String
getMessageId()
The message id this reaction is attached tolong
getMessageIdLong()
The message id this reaction is attached toPrivateChannel
getPrivateChannel()
MessageReaction.ReactionEmote
getReactionEmote()
TheReactionEmote
of this ReactionTextChannel
getTextChannel()
boolean
hasCount()
Whether this reaction can provide a count viagetCount()
.boolean
isFromType(ChannelType type)
Whether this Reaction was used in aMessageChannel
of the specifiedChannelType
.boolean
isSelf()
Whether the currently logged in account has reacted with this reactionRestAction<java.lang.Void>
removeReaction()
Removes this Reaction from the Message.RestAction<java.lang.Void>
removeReaction(User user)
Removes this Reaction from the Message.ReactionPaginationAction
retrieveUsers()
Retrieves theUsers
that already reacted with this MessageReaction.java.lang.String
toString()
-
-
-
Constructor Detail
-
MessageReaction
public MessageReaction(@Nonnull MessageChannel channel, @Nonnull MessageReaction.ReactionEmote emote, long messageId, boolean self, int count)
Creates a new MessageReaction instance- Parameters:
channel
- TheMessageChannel
this Reaction was used inemote
- TheReactionEmote
that was usedmessageId
- The message id this reaction is attached toself
- Whether we already reacted with this Reactioncount
- The amount of people that reacted with this Reaction
-
-
Method Detail
-
getJDA
@Nonnull public JDA getJDA()
The JDA instance of this Reaction- Returns:
- The JDA instance of this Reaction
-
isSelf
public boolean isSelf()
Whether the currently logged in account has reacted with this reactionThis will always be false for events. Discord does not provide this information for reaction events. You can use
MessageChannel.retrieveMessageById(String)
to get this information on a complete message.- Returns:
- True, if we reacted with this reaction
-
hasCount
public boolean hasCount()
Whether this reaction can provide a count viagetCount()
.
This is usually not provided for reactions coming fromMessageReactionAddEvent
or similar.- Returns:
- True, if a count is available
- See Also:
getCount()
-
getCount
public int getCount()
The amount of users that already reacted with this Reaction
This is not updated, it is afinal int
per Reaction instanceThis value is not available in events such as
MessageReactionAddEvent
andMessageReactionRemoveEvent
in which case anIllegalStateException
is thrown!- Returns:
- The amount of users that reacted with this Reaction
- Throws:
java.lang.IllegalStateException
- If this MessageReaction is from an event which does not provide a count
-
getChannelType
@Nonnull public ChannelType getChannelType()
TheChannelType
this Reaction was used in.- Returns:
- The ChannelType
-
isFromType
public boolean isFromType(@Nonnull ChannelType type)
Whether this Reaction was used in aMessageChannel
of the specifiedChannelType
.- Parameters:
type
- The ChannelType to compare- Returns:
- True, if this Reaction was used in a MessageChannel from the specified ChannelType
-
getGuild
@Nullable public Guild getGuild()
TheGuild
this Reaction was used in, this might returnnull
when this Reaction was not used in a MessageChannel from the ChannelTypeTEXT
!- Returns:
Guild
this Reaction was used in, ornull
-
getTextChannel
@Nullable public TextChannel getTextChannel()
- Returns:
- The
TextChannel
ornull
-
getPrivateChannel
@Nullable public PrivateChannel getPrivateChannel()
- Returns:
- The
PrivateChannel
ornull
-
getChannel
@Nonnull public MessageChannel getChannel()
TheMessageChannel
this Reaction was used in.- Returns:
- The channel this Reaction was used in
-
getReactionEmote
@Nonnull public MessageReaction.ReactionEmote getReactionEmote()
TheReactionEmote
of this Reaction- Returns:
- The final instance of this Reaction's Emote/Emoji
-
getMessageId
@Nonnull public java.lang.String getMessageId()
The message id this reaction is attached to- Returns:
- The message id this reaction is attached to
-
getMessageIdLong
public long getMessageIdLong()
The message id this reaction is attached to- Returns:
- The message id this reaction is attached to
-
retrieveUsers
@Nonnull @CheckReturnValue public ReactionPaginationAction retrieveUsers()
Retrieves theUsers
that already reacted with this MessageReaction.Possible ErrorResponses include:
UNKNOWN_MESSAGE
If the message this reaction was attached to got deleted.UNKNOWN_CHANNEL
If the channel this reaction was used in got deleted.MISSING_ACCESS
If we were removed from the channel/guild
- Returns:
ReactionPaginationAction
-
removeReaction
@Nonnull @CheckReturnValue public RestAction<java.lang.Void> removeReaction()
Removes this Reaction from the Message.
This will remove our own reaction as an overload ofremoveReaction(User)
.Possible ErrorResponses include:
UNKNOWN_MESSAGE
If the message this reaction was attached to got deleted.UNKNOWN_CHANNEL
If the channel this reaction was used in got deleted.MISSING_ACCESS
If we were removed from the channel/guild
- Returns:
RestAction
- Type: Void Nothing is returned on success
-
removeReaction
@Nonnull @CheckReturnValue public RestAction<java.lang.Void> removeReaction(@Nonnull User user)
Removes this Reaction from the Message.
This will remove the reaction of theUser
provided.If the provided User did not react with this Reaction this does nothing.
Possible ErrorResponses include:
UNKNOWN_MESSAGE
If the message this reaction was attached to got deleted.UNKNOWN_CHANNEL
If the channel this reaction was used in got deleted.MISSING_ACCESS
If we were removed from the channel/guild
- Parameters:
user
- The User of which to remove the reaction- Returns:
RestAction
Nothing is returned on success- Throws:
java.lang.IllegalArgumentException
- If the provideduser
is null.InsufficientPermissionException
- If the provided User is not us and we do not have permission tomanage messages
in the channel this reaction was used inPermissionException
- If the message is from another user in aPrivateChannel
-
clearReactions
@Nonnull @CheckReturnValue public RestAction<java.lang.Void> clearReactions()
Removes this entire reaction from the message.
UnlikeremoveReaction(User)
, which removes the reaction of a single user, this will remove the reaction completely.The following
ErrorResponses
are possible:MISSING_ACCESS
The currently logged in account lost access to the channel by either being removed from the guild or losing theVIEW_CHANNEL
permissionUNKNOWN_EMOJI
The provided unicode emoji doesn't exist. Try using one of the example formats.UNKNOWN_MESSAGE
The message was deleted.
- Returns:
RestAction
- Throws:
java.lang.UnsupportedOperationException
- If this reaction happened in a private channelInsufficientPermissionException
- If the currently logged in account does not havePermission.MESSAGE_MANAGE
in the channel- Since:
- 4.2.0
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-