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

buttonization doesn't work with custom emoji #15

Closed avurro closed 3 years ago

avurro commented 3 years ago

In buttonize method aren't handled custom emoji, as you can see:

public static void buttonize(@Nonnull Message msg, @Nonnull Map<String, BiConsumer<Member, Message>> buttons, boolean showCancelButton, @Nonnull Predicate<User> canInteract) throws ErrorResponseException, InsufficientPermissionException {
        if (!isActivated()) throw new InvalidStateException();
        Map<String, BiConsumer<Member, Message>> btns = Collections.unmodifiableMap(buttons);

        for (String k : btns.keySet()) {
            if (EmojiUtils.containsEmoji(k))
                msg.addReaction(k).submit();
            else
        --> -->    msg.addReaction(Objects.requireNonNull(msg.getJDA().getEmoteById(k))).submit();
        }
        ...

In this instruction: msg.addReaction(Objects.requireNonNull(msg.getJDA().getEmoteById(k))).submit(); You are trying to convert a custom emoji in Emote, failing: msg.getJDA().getEmoteById(k)

Please return the string directly instead, or make a double check: first find the Emote and in second place try it as custom emoji. msg.addReaction(k).submit();

Paginate method works like this.

ygimenez commented 3 years ago

Buttonize methods must only receive emoji unicodes or Emote IDs, and in the latest version (2.1.2) I standardized custom Emote usage to use only the ID instead of the mention.

This is because if you ever change your Emote's name, all buttons will stop working, so when using the ID to query for it this risk is removed.