Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require('discord.js'); // I'm requiring discord.js since we will be using Embeds.
  2.  
  3. exports.run = (client, message, args, tools) => {
  4.  
  5.   let pages = ['This is page one!', 'Second page', 'Third', 'You can add pages', 'All you need to do is add another item in the array', '**Supports markdown and regular chat description properties**']; // Here we will define an array of pages
  6.   let page = 1; // We will define what page we are on here, the default page will be 1. (You can change the default page)
  7.  
  8.   const embed = new Discord.MessageEmbed() // Define a new embed, if you are on the `stable` branch it will be new Discord.RichEmbed()
  9.     .setColor(0xffffff) // You can set your color here
  10.     .setFooter(`Page ${page} of ${pages.length}`) // This is the default value, showing the default page and the amount of pages in the array.
  11.     .setDescription(pages[page-1]) // This sets the description as the default page (we are subtracting 1 since arrays start at 0)
  12.  
  13.   message.channel.send(embed).then(msg => { // Now, we will send the embed and pass the new msg object
  14.    
  15.     msg.react('⏪').then( r => { // We need to make sure we start the first two reactions, this is the first one
  16.       msg.react('⏩') // This is the second one, it will run this one after the first one
  17.      
  18.       // Filters - These make sure the variables are correct before running a part of code
  19.       const backwardsFilter = (reaction, user) => reaction.emoji.name === '⏪' && user.id === message.author.id;
  20.       const forwardsFilter = (reaction, user) => reaction.emoji.name === '⏩' && user.id === message.author.id; // We need two filters, one for forwards and one for backwards
  21.      
  22.       const backwards = msg.createReactionCollector(backwardsFilter, { time: 60000 }); // This creates the collector, which has the filter passed through it. The time is in milliseconds so you can change that for however you want the user to be able to react
  23.       const forwards = msg.createReactionCollector(forwardsFilter, { time: 60000 }); // This is the second collector, collecting for the forwardsFilter
  24.      
  25.       // Next, we need to handle the collections
  26.       backwards.on('collect', r => { // This runs when the backwards reaction is found
  27.         if (page === 1) return; // We want to make sure if they are on the first page, they cant go back a page.
  28.         page--; // If it can go back, push back the page number
  29.         embed.setDescription(pages[page-1]); // Just like setting the first one, reset the Description to the new page
  30.         embed.setFooter(`Page ${page} of ${pages.length}`); // This also sets the footer to view the current pagenumber
  31.         msg.edit(embed) // Then, we can push the edit to the message
  32.       })
  33.      
  34.       forwards.on('collect', r => { // This runs when the forwards reaction is found
  35.         if (page === pages.length) return; // We can use copy and paste since it is basically the same thing, although now it checks if the page is currently on the highest possible, so it can't go any higher.
  36.         page++; // If it can go forwards, push forwards the page number
  37.         embed.setDescription(pages[page-1]); // Just like setting the first one, reset the Description to the new page
  38.         embed.setFooter(`Page ${page} of ${pages.length}`); // This also sets the footer to view the current pagenumber
  39.         msg.edit(embed) // Then, we can push the edit to the message
  40.       })
  41.    
  42.     })
  43.  
  44.   })
  45.  
  46. }
  47.  
  48. // ⏪⏩
  49. // Now, we can test it. Make sure you add some pages though.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement