Class 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
    • Constructor Detail

      • MessageReaction

        public MessageReaction​(MessageChannel channel,
                               MessageReaction.ReactionEmote emote,
                               long messageId,
                               boolean self,
                               int count)
        Creates a new MessageReaction instance
        Parameters:
        channel - The MessageChannel this Reaction was used in
        emote - The ReactionEmote that was used
        messageId - The message id this reaction is attached to
        self - Whether we already reacted with this Reaction
        count - The amount of people that reacted with this Reaction
    • Method Detail

      • getJDA

        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 reaction
        Returns:
        True, if we reacted with this reaction
      • getCount

        public int getCount()
        The amount of users that already reacted with this Reaction
        This is not updated, it is a final int per Reaction instance

        This value is not available in events such as MessageReactionAddEvent and MessageReactionRemoveEvent in which case an IllegalStateException 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

        public ChannelType getChannelType()
        The ChannelType this Reaction was used in.
        Returns:
        The ChannelType
      • isFromType

        public boolean isFromType​(ChannelType type)
        Whether this Reaction was used in a MessageChannel of the specified ChannelType.
        Parameters:
        type - The ChannelType to compare
        Returns:
        True, if this Reaction was used in a MessageChannel from the specified ChannelType
      • getGuild

        public Guild getGuild()
        The Guild this Reaction was used in, this might return null when this Reaction was not used in a MessageChannel from the ChannelType TEXT!
        Returns:
        Guild this Reaction was used in, or null
      • getChannel

        public MessageChannel getChannel()
        The MessageChannel this Reaction was used in.
        Returns:
        The channel this Reaction was used in
      • getMessageId

        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
      • getUsers

        @CheckReturnValue
        public ReactionPaginationAction getUsers​(int amount)
        Retrieves the Users that already reacted with this MessageReaction. The maximum amount of users that can be retrieved is 100.

        Possible ErrorResponses include:

        Parameters:
        amount - the amount of users to retrieve
        Returns:
        ReactionPaginationAction
        Retrieves an immutable list of users that reacted with this Reaction.
        Throws:
        java.lang.IllegalArgumentException - if the provided amount is not between 1-100
      • removeReaction

        @CheckReturnValue
        public RestAction<java.lang.Void> removeReaction()
        Removes this Reaction from the Message.
        This will remove our own reaction as an overload of removeReaction(User).

        Possible ErrorResponses include:

        Returns:
        RestAction - Type: Void Nothing is returned on success
      • removeReaction

        @CheckReturnValue
        public RestAction<java.lang.Void> removeReaction​(User user)
        Removes this Reaction from the Message.
        This will remove the reaction of the User provided.

        If the provided User did not react with this Reaction this does nothing.

        Possible ErrorResponses include:

        Parameters:
        user - The User of which to remove the reaction
        Returns:
        RestAction - Type: Void Nothing is returned on success
        Throws:
        java.lang.IllegalArgumentException - If the provided user is null.
        InsufficientPermissionException - if the provided User is not us and we do not have permission to manage messages in the channel this reaction was used in
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object