ygimenez / Pagination-Utils

A collection of methods to make message pagination with JDA easier.
GNU Lesser General Public License v2.1
27 stars 7 forks source link

Error when using library in DM #9

Closed p5nbTgip0r closed 3 years ago

p5nbTgip0r commented 3 years ago

Checklist

Make sure that you've checked all the items below.

Library info

What libraries versions are you using.

Describe the bug

When executing Pages.paginate on a message that was sent in a DM with a user, the library attempts to set the timeout variable by calling msg.clearReactions(). This throws an exception because the bot cannot clear reactions from a message in a DM:

java.lang.IllegalStateException: Cannot clear reactions from a message in a Group or PrivateChannel.
    at net.dv8tion.jda.internal.entities.ReceivedMessage.clearReactions(ReceivedMessage.java:175) ~[JDA-4.2.0_225.jar:4.2.0_225]
    at com.github.ygimenez.method.Pages$1.<init>(Pages.java:138) ~[Pagination-Utils-2.0.0.jar:na]
    at com.github.ygimenez.method.Pages.paginate(Pages.java:131) ~[Pagination-Utils-2.0.0.jar:na]

After the exception is thrown, the reactions will not change pages anymore.

To Reproduce

Steps to reproduce the behavior:

  1. Open a private channel with a user, or execute a command in a DM with the bot that will cause a paged message/embed to be created.
  2. Call Pages.paginate on the message that was sent from the bot user in the DM channel
  3. An exception should be thrown and the pages will not change upon reacting

Expected behavior

There shouldn't be any exceptions thrown and the buttons should respond. The timeout variable should probably be changed to call removeReaction on all of the individual reactions added by the bot if the message is in a private channel or group. There's probably some more stuff that needs to be added in order to support private channels/groups, like detecting both reaction add and remove in order to change pages.

Screenshots

N/A

Additional context

It seems like this problem was fixed in #5 but with the release of 2.0.0 the fix may have gotten replaced with code which doesn't support private channels/groups.

ygimenez commented 3 years ago

The fix for this bug is being tested and you'll be updated once a release is available.

ygimenez commented 3 years ago

Issue fixed in release 2.1.1