BasicReplyPagination.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 } = 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. //These very intents are needed.
  25. //For DMs use IntentBitField.Flags.DirectMessages instead of Guilds and GuildMessages.
  26. const client = new Client({intents: [IntentsBitField.Flags.GuildMessages, IntentsBitField.Flags.Guilds, IntentsBitField.Flags.MessageContent]});
  27. //Ready!
  28. client.once("ready", async () => {
  29. console.log("Ready!");
  30. });
  31. //Catch command.
  32. client.on("messageCreate", async (message) => {
  33. if (message.content === "!pages")
  34. {
  35. //Setup pagination.
  36. const pagination = new PaginationWrapper()
  37. .setButtons(buttons)
  38. .setEmbeds(embeds)
  39. .setTime(60000);
  40. //Send it as a reply to a certain message.
  41. await pagination.reply(message);
  42. //Alternative way.
  43. //await pagination.send(message.channel, {reply: {messageReference: message}});
  44. };
  45. });
  46. //Login.
  47. client.login("yourToken");