discord.js-pagination icon indicating copy to clipboard operation
discord.js-pagination copied to clipboard

Index.js Up Adaptation for v13

Open Toamix opened this issue 2 years ago • 0 comments

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;

Toamix avatar Mar 03 '22 13:03 Toamix