BasicInteractionPagination.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const {MessageEmbed, Client, MessageButton, Intents} = require('discord.js');
  2. const {NextPageButton, PreviousPageButton, InteractionPagination} = require("djs-button-pages");
  3. //Array of embeds for pagination.
  4. const embeds =
  5. [
  6. new MessageEmbed().setColor("RANDOM").setDescription("First page!"),
  7. new MessageEmbed().setColor("RANDOM").setDescription("Wow! It's second page!"),
  8. new MessageEmbed().setColor("RANDOM").setDescription("Unbelivable! Third class page!"),
  9. new MessageEmbed().setColor("RANDOM").setDescription("Not possible! Fourth page!"),
  10. new MessageEmbed().setColor("RANDOM").setDescription("Not probable! Special fifth page!"),
  11. new MessageEmbed().setColor("RANDOM").setDescription("Progress! It's page with number six that is stored with number five!"),
  12. new MessageEmbed().setColor("RANDOM").setDescription("You're feeling with determination because of the seven page!"),
  13. new MessageEmbed().setColor("RANDOM").setDescription("You shall not pass! It's the last and the latest page!"),
  14. ]
  15. //Array of buttons for pagination.
  16. const buttons =
  17. [
  18. new PreviousPageButton(new MessageButton().setCustomId("prev").setLabel("Previous").setStyle("PRIMARY")),
  19. new NextPageButton(new MessageButton().setCustomId("next").setLabel("Next").setStyle("PRIMARY")),
  20. //ALSO CAN BE: new NextPageButton().setStyle(new MessageButton().setCustomId("next").setLabel("Next").setStyle("PRIMARY"))
  21. ]
  22. //Client flags are not needed for this example of usage.
  23. const client = new Client({intents: []});
  24. //Replace YOUR TOKEN with the token from Discord Developer Portal.
  25. client.login("YOUR TOKEN");
  26. //Ready!
  27. client.once("ready", async () => {
  28. console.log("ready");
  29. //Create guild command (Replace YOUR GUILD with the GuildID of you Guild). If you want to make global command head to Discord.JS documentation.
  30. const guild = await client.guilds.fetch("YOUR GUILD");
  31. guild.commands.create({name: "pages", description: "Sample pages."});
  32. });
  33. //On interaction.
  34. client.on("interactionCreate", async (interaction) => {
  35. if (interaction.isCommand() && interaction.commandName === "pages")
  36. {
  37. const pagination = await new InteractionPagination() //Create pagination.
  38. .setButtons(buttons) //Pass buttons.
  39. .setEmbeds(embeds) //Pass embeds.
  40. .setTime(60000) //Set life-time to 60000.
  41. .send(interaction); //Send.
  42. };
  43. });