@quantiom/pagemenu
v2.0.8
Published
Send dynamic discord embed menus, with pages controlled by reactions.
Downloads
42
Maintainers
Readme
#pageMenu
With pageMenu, you can send "menus" on discord, which are controlled by reactions, thanks to Discord.JS.
Example
##Install
npm install @quantiom/pagemenu
##Usage
const Discord = require('discord.js');
const client = new Discord.Client();
const pageMenu = require('@quantiom/pagemenu');
client.on("message", (message) => {
...
// new pageMenu(message, [pages], {options});
let pMenu = new pageMenu(message,
[
{
title: "title1",
description: "this is page 1",
function: function() { console.log("page 1"); }, // this function will be executed when the user goes to this page
thumbnail: 'insert url here',
fields: [
{
name: "test",
value: "field_desc",
inline: true
},
{
name: "test1",
value: "field1_desc (not inline)",
inline: false
}
],
color: "ffffff", // white
url: "https://google.com",
timestamp: true // sets the timestamp, *timestamp is not required, you don't have to do timestamp: false*.
},
{ title: "title2", description: "this is page 2", function: function() { console.log("page 2"); }, image: 'insert url here'},
{ title: "title3", description: "this is page 3"}, // these are the only options required for a page
{ title: "title4", description: "this is page 4"}
], /*options*/ {duration: 60000, expireFunction: function(msg) { msg.delete(); }});
// the expire function will delete the page message once it's expired (based on duration)
pMenu.getPage(0).setTitle("test"); // sets the title of page 0 (the first page) to "test"
pMenu.pages[0].setTitle("test"); // same thing as above
pMenu.getPage(1).addField("this is an inline field", "pretty cool", true); // adds an inline field to page 2
pMenu.getPage(1).addField("this is a field", "epic"); // adds a non-inline field to page 2
pMenu.getPage(1).setTimestamp(); // adds a timestamp to the page
pMenu.addPages([{title: "blabla", description: "this is a description for the newly added page."}]).then(pages => console.log(pages));
pMenu.run();
}
##Options
duration
- how long the pagemenu will last in milliseconds, default 60000.emojis
- the emojis used to control the menu, they will do the same as the default ones.waitingColor
- the color while the reactions are being added, default is black.waitingText
- the text while the reactions are being added, default "Waiting..."expireFunction(message)
- this function will be called when the pagemenu duration has expired, by default, it will edit the message to "Page menu expired"
#Methods
run()
Starts the pageMenu and other events.
getPage(index)
Gets the page object from index (starts at 0 of course, 0 = page 1);
addPage(page)
Adds a page to the menu.
addPages([pages])
Adds multiple pages to the menu, pass an array of pages.
removePage(index)
Removes a page from the menu with the index passed.
removePages([indices])
Removes multiple pages, pass an array of indices.
swapPages(index1, index2)
Swaps two pages.
reversePages()
Reverses the order of the pages.
#Page Options
title
requireddescription
requiredthumbnail
image
fields
- an array of objects withname
,value
, andinline
timestamp
- just set it to true (no need to set it to false because this is not required)url
color
#Page Methods
setTitle(title)
setDescription(description)
setFunction(function)
<page>.setFunction(function(){ console.log("hello!") });
setThumbnail(URL or file path)
setImage(URL or file path)
addField(name, value, inline = false)
addBlankField(inline = false)
setTimestamp()
setURL(url)
<page>.setURL("https://youtube.com");
setColor(color)
<page>.setColor("fffff");