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

I need a usage example #7

Closed avurro closed 3 years ago

avurro 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

I can't in any way to make the pagination. Not even copying and pasting the code in README. Could you please write me a complete whole code?

Expected behavior

A complete sample code that I can copy and paste

ygimenez commented 3 years ago

Could you show me how you're doing it? Also, what kind of issues are you having?

avurro commented 3 years ago

Only the first page appears, the buttons do not appear. Code follows:

List<Page> pages = new ArrayList<>();
for (Entry<String, List<Class<?>>> page : this.commandsCategory.entrySet())
    pages.add(makePage(event, page.getKey(), page.getValue()));

event.getChannel().sendMessage((Message) pages.get(0).getContent()).queue(success -> {
            Pages.paginate(success, pages, 60, TimeUnit.SECONDS);
});

private Page makePage(MessageReceivedEvent event, String category, List<Class<?>> commandsClasses) {

    MessageBuilder eb = new MessageBuilder();
    eb.setContent("text");
    return new Page(PageType.TEXT, eb.build());
}

In Main:

public static void main(String[] args){
   ...      
   try {
            jda = JDABuilder.createLight(getBottoken(), GatewayIntent.GUILD_MESSAGES)
                    .addEventListeners(new MessageListener())
                    .build();
            jda.awaitReady();
            Pages.activate(jda);
   } catch (LoginException e) {
   ...
avurro commented 3 years ago

Can you please just write me a complete working piece of code?

ygimenez commented 3 years ago

Your code is correct, do you get any error in the console? If you use EmbedBuilder instead of MessageBuilder does it work?

avurro commented 3 years ago

Same result with EmbedBuilder. Can you please just write me a complete working piece of code that I can copy and paste?

ygimenez commented 3 years ago

Does this work? Please check the console for any error.

List<Page> pages = new ArrayList<>();

EmbedBuilder eb = new EmbedBuilder();
for (int i = 0; i < 5; i++) {
    eb.setDescription("Test " + i);
    pages.add(new Page(PageType.EMBED, eb.build()));
} 

event.getChannel().sendMessage((MessageEmbed) pages.get(0).getContent()).queue(s -> {
    Pages.paginate(s, pages, 60, TimeUnit.SECONDS);
});
avurro commented 3 years ago

image Are you sure your code works? Can you try it yourself please?

ygimenez commented 3 years ago

It does work, I use it exactly like that in my bot's code, are you sure you have all the required permissions? Could you please check if no exception were thrown in the console?

avurro commented 3 years ago

No exceptions are thrown, it just doesn't work. Can you show me how you set up JDA?

are you sure you have all the required permissions?

My bot has admin permissions

avurro commented 3 years ago

I finally understood what the problem is, the bot must have the following explicit intentions:

GatewayIntent.GUILD_MESSAGES
GatewayIntent.GUILD_MESSAGE_REACTIONS

I am using JDABuilder.createLight and these permissions are not set by default as is the case with JDABuilder.createDefault which is what you probably use.

You should make this explicit in the documentation.

ygimenez commented 3 years ago

Honesty I didn't know createLight removed such basic intents, I'll add a note about it next to required permissions. Thanks for pointing out the solution.