Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {
MessageActionRow,
ActionRowBuilder,
Message,
MessageEmbed,
MessageButton,
Expand All @@ -21,15 +21,16 @@ const paginationEmbed = async (
) => {
if (!pages) throw new Error("Pages are not given.");
if (!buttonList) throw new Error("Buttons are not given.");
if (buttonList[0].style === "LINK" || buttonList[1].style === "LINK")
if (buttonList.components[0].style === "LINK" || buttonList.components[1].style === "LINK")
throw new Error(
"Link buttons are not supported with discordjs-button-pagination"
);
if (buttonList.length !== 2) throw new Error("Need two buttons.");

if (buttonList.components.length !== 2) throw new Error("Need two buttons.");

let page = 0;

const row = new MessageActionRow().addComponents(buttonList);
const row = new ActionRowBuilder().addComponents(buttonList.components);

//has the interaction already been deferred? If not, defer the reply.
if (interaction.deferred == false) {
Expand All @@ -43,20 +44,21 @@ const paginationEmbed = async (
});

const filter = (i) =>
i.customId === buttonList[0].customId ||
i.customId === buttonList[1].customId;
i.custom_id === buttonList.components[1].custom_id ||
i.custom_id === buttonList.components[0].custom_id;

const collector = await curPage.createMessageComponentCollector({
filter,
time: timeout,
});

collector.on("collect", async (i) => {

switch (i.customId) {
case buttonList[0].customId:
case buttonList.components[0].data.custom_id:
page = page > 0 ? --page : pages.length - 1;
break;
case buttonList[1].customId:
case buttonList.components[1].data.custom_id:
page = page + 1 < pages.length ? ++page : 0;
break;
default:
Expand All @@ -72,9 +74,9 @@ const paginationEmbed = async (

collector.on("end", (_, reason) => {
if (reason !== "messageDelete") {
const disabledRow = new MessageActionRow().addComponents(
buttonList[0].setDisabled(true),
buttonList[1].setDisabled(true)
const disabledRow = new ActionRowBuilder().addComponents(
buttonList.components[0].setDisabled(true),
buttonList.components[1].setDisabled(true)
);
curPage.edit({
embeds: [pages[page].setFooter({ text: `Page ${page + 1} / ${pages.length}` })],
Expand Down