PageTravelButton.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //Imports.
  2. const { Client, EmbedBuilder, ButtonStyle, IntentsBitField } = require("discord.js");
  3. const { PaginationWrapper } = require("djs-button-pages");
  4. //Pre-made buttons.
  5. const { NextPageButton, PreviousPageButton, PageTravelButton } = 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. //Page travel button. By default page travel lasts 15 seconds. You can also change some tips that PageTravelButton produces. Or disable them by setting them undefined.
  24. new PageTravelButton({custom_id: "travel_page", emoji: "✈", style: ButtonStyle.Primary}),
  25. ];
  26. //These very bitfields may be needed. The first one will be definetely needed.
  27. const client = new Client({intents: [IntentsBitField.Flags.MessageContent, IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages, IntentsBitField.Flags.DirectMessages]});
  28. //Ready!
  29. client.once("ready", async () => {
  30. console.log("Ready!");
  31. //Fetch the guild you need.
  32. const guild = await client.guilds.fetch("yourGuildId");
  33. //Add command.
  34. guild.commands.create({name: "pages", description: "Testing DJS-Button-Pages!"});
  35. });
  36. //Catch command.
  37. client.on("interactionCreate", async (interaction) => {
  38. if (interaction.isCommand() && interaction.commandName === "pages")
  39. {
  40. //Setup pagination.
  41. const pagination = new PaginationWrapper()
  42. .setButtons(buttons)
  43. .setEmbeds(embeds)
  44. .setTime(60000);
  45. //Send as a reply to an interaction.
  46. await pagination.interactionReply(interaction);
  47. };
  48. });
  49. //Login.
  50. client.login("yourToken");