Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index.js Up Adaptation for v13 #42

Open
wants to merge 176 commits into
base: master
Choose a base branch
from
Open

Index.js Up Adaptation for v13 #42

wants to merge 176 commits into from

Conversation

Toamix
Copy link

@Toamix Toamix commented Mar 3, 2022

const paginationEmbed = async (msg, pages, emojiList = ['⏪', '⏩'], timeout = 120000) => {
if (!msg && !msg.channel) throw new Error('Channel is inaccessible.');
if (!pages) throw new Error('Pages are not given.');
if (emojiList.length !== 2) throw new Error('Need two emojis.');
let page = 0;
const curPage = await msg.channel.send({ embeds: [pages[page].setFooter({ text: Page ${page + 1} / ${pages.length}})]});
for (const emoji of emojiList) await curPage.react(emoji);
const reactionCollector = curPage.createReactionCollector(
(reaction, user) => emojiList.includes(reaction.emoji.name) && !user.bot,
{ time: timeout }
);
reactionCollector.on('collect', reaction => {
reaction.users.remove(msg.author);
switch (reaction.emoji.name) {
case emojiList[0]:
page = page > 0 ? --page : pages.length - 1;
break;
case emojiList[1]:
page = page + 1 < pages.length ? ++page : 0;
break;
default:
break;
}
curPage.edit({ embeds: [pages[page].setFooter({ text: Page ${page + 1} / ${pages.length}})]});
});
reactionCollector.on('end', () => {
if (!curPage.deleted) {
curPage.reactions.removeAll()
}
});
return curPage;
};
module.exports = paginationEmbed;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants