Added options to pagination edit calls
This commit is contained in:
parent
b4320303ce
commit
21f4a5a51a
1 changed files with 7 additions and 6 deletions
|
@ -3,8 +3,7 @@ const MessageCollector = require("./awaitmessages.js");
|
||||||
|
|
||||||
module.exports = async (client, message, pages, timeout = 120000) => {
|
module.exports = async (client, message, pages, timeout = 120000) => {
|
||||||
const manageMessages = message.channel.guild && message.channel.permissionsOf(client.user.id).has("manageMessages") ? true : false;
|
const manageMessages = message.channel.guild && message.channel.permissionsOf(client.user.id).has("manageMessages") ? true : false;
|
||||||
let page = 0;
|
const options = {
|
||||||
let currentPage = await client.createMessage(message.channel.id, Object.assign(pages[page], {
|
|
||||||
messageReference: {
|
messageReference: {
|
||||||
channelID: message.channel.id,
|
channelID: message.channel.id,
|
||||||
messageID: message.id,
|
messageID: message.id,
|
||||||
|
@ -14,7 +13,9 @@ module.exports = async (client, message, pages, timeout = 120000) => {
|
||||||
allowedMentions: {
|
allowedMentions: {
|
||||||
repliedUser: false
|
repliedUser: false
|
||||||
}
|
}
|
||||||
}));
|
};
|
||||||
|
let page = 0;
|
||||||
|
let currentPage = await client.createMessage(message.channel.id, Object.assign(pages[page], options));
|
||||||
const emojiList = ["◀", "🔢", "▶", "🗑"];
|
const emojiList = ["◀", "🔢", "▶", "🗑"];
|
||||||
for (const emoji of emojiList) {
|
for (const emoji of emojiList) {
|
||||||
await currentPage.addReaction(emoji);
|
await currentPage.addReaction(emoji);
|
||||||
|
@ -25,7 +26,7 @@ module.exports = async (client, message, pages, timeout = 120000) => {
|
||||||
switch (reaction.name) {
|
switch (reaction.name) {
|
||||||
case "◀":
|
case "◀":
|
||||||
page = page > 0 ? --page : pages.length - 1;
|
page = page > 0 ? --page : pages.length - 1;
|
||||||
currentPage = await currentPage.edit(pages[page]);
|
currentPage = await currentPage.edit(Object.assign(pages[page], options));
|
||||||
if (manageMessages) msg.removeReaction("◀", member.id);
|
if (manageMessages) msg.removeReaction("◀", member.id);
|
||||||
break;
|
break;
|
||||||
case "🔢":
|
case "🔢":
|
||||||
|
@ -48,7 +49,7 @@ module.exports = async (client, message, pages, timeout = 120000) => {
|
||||||
if (await client.getMessage(askMessage.channel.id, askMessage.id).catch(() => undefined)) askMessage.delete();
|
if (await client.getMessage(askMessage.channel.id, askMessage.id).catch(() => undefined)) askMessage.delete();
|
||||||
if (manageMessages) await response.delete();
|
if (manageMessages) await response.delete();
|
||||||
page = Number(response.content) - 1;
|
page = Number(response.content) - 1;
|
||||||
currentPage = await currentPage.edit(pages[page]);
|
currentPage = await currentPage.edit(Object.assign(pages[page], options));
|
||||||
if (manageMessages) msg.removeReaction("🔢", member.id);
|
if (manageMessages) msg.removeReaction("🔢", member.id);
|
||||||
});
|
});
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
@ -57,7 +58,7 @@ module.exports = async (client, message, pages, timeout = 120000) => {
|
||||||
break;
|
break;
|
||||||
case "▶":
|
case "▶":
|
||||||
page = page + 1 < pages.length ? ++page : 0;
|
page = page + 1 < pages.length ? ++page : 0;
|
||||||
currentPage = await currentPage.edit(pages[page]);
|
currentPage = await currentPage.edit(Object.assign(pages[page], options));
|
||||||
if (manageMessages) msg.removeReaction("▶", member.id);
|
if (manageMessages) msg.removeReaction("▶", member.id);
|
||||||
break;
|
break;
|
||||||
case "🗑":
|
case "🗑":
|
||||||
|
|
Loading…
Reference in a new issue