BasicInteractionPagination.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //Imports.
  2. const { Client, EmbedBuilder, ButtonStyle } = require("discord.js");
  3. const { PaginationWrapper } = require("djs-button-pages");
  4. //Pre-made buttons.
  5. const { NextPageButton, PreviousPageButton } = require('@djs-button-pages/presets');
  6. //Array of embeds for pagination.
  7. const embeds =
  8. [
  9. new EmbedBuilder().setColor("Aqua").setTitle("Test!").setDescription("Whoosh! Your first page!"),
  10. new EmbedBuilder().setColor("Blurple").setTitle("Test!").setDescription("Wow! It's a second one!"),
  11. new EmbedBuilder().setColor("DarkAqua").setTitle("Test!").setDescription("Unbelivable! Third page is available to be bought for 20$!"),
  12. new EmbedBuilder().setColor("DarkGold").setTitle("Test!").setDescription("Not possible! This is my fourth page!"),
  13. new EmbedBuilder().setColor("Gold").setTitle("Test!").setDescription("Not probable! Special fifth page!"),
  14. new EmbedBuilder().setColor("DarkButNotBlack").setTitle("Test!").setDescription("Wow! Another page..."),
  15. new EmbedBuilder().setColor("White").setTitle("Test!").setDescription("Don't tell me that it is page number seven!"),
  16. new EmbedBuilder().setColor("Red").setTitle("Oh, wow!").setDescription("Looks like it is the last page("),
  17. ];
  18. //Array of buttons for pagination.
  19. const buttons =
  20. [
  21. new PreviousPageButton({custom_id: "prev_page", emoji: "◀", style: ButtonStyle.Secondary}),
  22. new NextPageButton({custom_id: "next_page", emoji: "▶", style: ButtonStyle.Secondary}),
  23. ];
  24. //No intents needed.
  25. const client = new Client({intents: []});
  26. //Ready!
  27. client.once("ready", async () => {
  28. console.log("Ready!");
  29. //Fetch guild that is needed.
  30. const guild = await client.guilds.fetch("yourGuildId");
  31. //Add command.
  32. guild.commands.create({name: "pages", description: "Testing DJS-Button-Pages!"});
  33. });
  34. //Catch command.
  35. client.on("interactionCreate", async (interaction) => {
  36. if (interaction.isCommand() && interaction.commandName === "pages")
  37. {
  38. //Setup pagination.
  39. const pagination = new PaginationWrapper()
  40. .setButtons(buttons)
  41. .setEmbeds(embeds)
  42. .setTime(60000);
  43. //Send it as a reply to interaction.
  44. await pagination.interactionReply(interaction);
  45. };
  46. });
  47. //Login.
  48. client.login("yourToken");