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

Buttons being removed from other embeds #49

Closed ItsLewizzz closed 11 months ago

ItsLewizzz commented 1 year ago

Checklist

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

Library info

What libraries versions are you using.

Describe the bug

When I add an ActionRow to other embeds I have in my bot (that are not handled by Pagination-Utils), as soon as I react on any button the whole row is deleted. When the util was disabled my other embed buttons worked fine without being deleted.

To Reproduce

Steps to reproduce the behavior:

  1. Create external embed with buttons
  2. Interact with one of the buttons
  3. The whole action row will be deleted.

Expected behavior

Pagination Utils should not be handling other embed button listeners.

Screenshots

If applicable, add screenshots to help explain your problem.

With Pagination-Utils enabled on external embed with "buttons" that is handled by myself on my own listener. image

With Pagination-Utils disabled (working fine, my buttons show and are usable): image

Additional context

Add any other context about the problem here.

ygimenez commented 1 year ago

This happens because the library assumes all button handling will be done by itself (like with Pages.buttonize), I'll add a setting to make it ignore buttons not created through its methods on the next update.

Meanwhile, you can manually add the message to the events map through Pages.getHandler().addEvent(message, null), the second argument says non-null but it won't cause errors as it checks whether the consumer is null, just remember to manually remove the event afterwards, else it'll stay until you shutdown the bot (possibly causing a memory leak).

ItsLewizzz commented 11 months ago

Is there any ETA for this?

ygimenez commented 11 months ago

Sorry, I've been busy with some tasks at work, couldn't touch it yet, but I should be able to deal with it soon.

ygimenez commented 11 months ago

I apologize for the confusion, the solution was already available (but in a different class) since version 4.0.0, but I forgot about it.

(Available in version 4.0.6)

To fix the issue you're having, simply change setOnRemove() in PaginatorBuilder to anything else (eg. an empty consumer). The default action is to remove the interactions from the message, changing it will allow you to do something else (or even leverage it as a way to get the events for your own handler).

var paginator = PaginatorBuilder.createPaginator(/* Your client */)
        ... // Other settings
        .setOnRemove(hook -> {}) // Setting it as an empty consumer will suffice, or your can use it for other things.
        .build()