Class MessageReaction

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

        @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 reaction

        This 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 via getCount().
        This is usually not provided for reactions coming from MessageReactionAddEvent 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 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

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

        public boolean isFromType​(@Nonnull
                                  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

        @Nullable
        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

        @Nonnull
        public MessageChannel getChannel()
        The MessageChannel this Reaction was used in.
        Returns:
        The channel this Reaction was used in
      • 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
      • removeReaction

        @Nonnull
        @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

        @Nonnull
        @CheckReturnValue
        public RestAction<java.lang.Void> removeReaction​(@Nonnull
                                                         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 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
        PermissionException - If the message is from another user in a PrivateChannel
      • clearReactions

        @Nonnull
        @CheckReturnValue
        public RestAction<java.lang.Void> clearReactions()
        Removes this entire reaction from the message.
        Unlike removeReaction(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 the VIEW_CHANNEL permission
        • UNKNOWN_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 channel
        InsufficientPermissionException - If the currently logged in account does not have Permission.MESSAGE_MANAGE in the channel
        Since:
        4.2.0
      • 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