BasicInteractionPagination.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //Imports.
  2. const { Client, EmbedBuilder, ButtonStyle } = require("discord.js");
  3. const { InteractionPagination, NextPageButton, PreviousPageButton } = require("djs-button-pages");
  4. //Array of embeds for pagination.
  5. const embeds =
  6. [
  7. new EmbedBuilder().setDescription("First page!"),
  8. new EmbedBuilder().setDescription("Wow! It's second page!"),
  9. new EmbedBuilder().setDescription("Unbelivable! Third class page!"),
  10. new EmbedBuilder().setDescription("Not possible! Fourth page!"),
  11. new EmbedBuilder().setDescription("Not probable! Special fifth page!"),
  12. new EmbedBuilder().setDescription("Progress! It's page with number six that is stored with number five!"),
  13. new EmbedBuilder().setDescription("You're feeling with determination because of the seven page!"),
  14. new EmbedBuilder().setDescription("You shall not pass! It's the last and the latest page!"),
  15. ];
  16. //Array of buttons for pagination.
  17. const buttons =
  18. [
  19. new PreviousPageButton({custom_id: "prev_page", label: "Previous", style: ButtonStyle.Success}), //Style can be passed either in constructor.
  20. new NextPageButton().setStyle({custom_id: "next_page", label: "Next", style: ButtonStyle.Success}), //Or in special method.
  21. ];
  22. //No intents needed for this example.
  23. const client = new Client({intents: []});
  24. //Ready signal!
  25. client.once("ready", async () => {
  26. console.log("Ready!");
  27. //Search for guild. Replace YOUR GUILD ID with your guild id.
  28. const guild = await client.guilds.fetch("YOUR GUILD ID");
  29. guild.commands.create({name: "pages", description: "Sample pages."});
  30. });
  31. //Action on interaction.
  32. client.on("interactionCreate", async (interaction) => {
  33. //If user used pages command.
  34. if (interaction.isCommand() && interaction.commandName === "pages")
  35. {
  36. const pagination = new InteractionPagination() //Create pagination.
  37. .setButtons(buttons) //Insert buttons.
  38. .setEmbeds(embeds) //Add embeds.
  39. .setTime(60000); //Set time.
  40. await pagination.send(interaction); //Send!
  41. };
  42. });
  43. //Login. Replace YOUR TOKEN with token from Discord Developer Portal!
  44. client.login("YOUR TOKEN");