Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType, Component, } = require('discord.js');
- module.exports = async (interaction, pages, time = 30 * 1000) => {
- try {
- if (!interaction || !pages || !pages > 0) throw new Error(`Invalid arguments 3!`);
- await interaction.deferReply();
- if (pages.length === 1) {
- return await interaction.editReply({
- embeds: pages,
- components: [],
- fetchReply: true
- })
- }
- const prev = new ButtonBuilder()
- .setCustomId('prevmenu')
- .setEmoji('⬅')
- .setStyle(ButtonStyle.Primary)
- .setDisabled(true)
- const home = new ButtonBuilder()
- .setCustomId('homemenu')
- .setEmoji('🏠')
- .setStyle(ButtonStyle.Secondary)
- .setDisabled(true)
- const next = new ButtonBuilder()
- .setCustomId('nextmenu')
- .setEmoji('➡')
- .setStyle(ButtonStyle.Primary)
- const buttons = new ActionRowBuilder()
- .addComponents([prev, home, next]);
- let index = 0
- const msg = await interaction.editReply({
- embeds: [pages[index]],
- components: [buttons],
- fetchReply: true
- });
- const mc = await msg.createMessageComponentCollector({
- componentType: ComponentType.Button,
- time,
- });
- mc.on(`collect`, async (i) => {
- await console.log(0)
- if (i.user.id !== interaction.user.id) return await i.reply({ content: `You are not allowed to do this`, ephemeral: true });
- await console.log(1)
- await i.deferUpdate();
- await console.log(2)
- if (i.setCustomId === 'prevmenu') {
- await console.log(3)
- if (index > 0) {
- await console.log(4)
- await index--
- await console.log(5)
- } else if (i.CustomId === 'homemenu') {
- await console.log(6)
- index = 0
- await console.log(7)
- } else if (i.CustomId === 'nextmenu') {
- await console.log(8)
- if (index < pages.length - 1) {
- await console.log(9)
- await index++
- await console.log(10)
- }
- await console.log(11)
- }
- await console.log(12)
- if (index === 0) {
- await console.log(13)
- await prev.setDisabled(true);
- await console.log(14)
- await home.setDisabled(true);
- await console.log(15)
- } else {
- await console.log(16)
- await prev.setDisabled(false);
- await console.log(17)
- await home.setDisabled(false);
- await console.log(18)
- }
- await console.log(19)
- if (index === pages.length - 1) {
- await console.log(20)
- await next.setDisabled(true)
- await console.log(21)
- } else {
- await console.log(22)
- await next.setDisabled(false);
- await console.log(23)
- }
- await console.log(24)
- await msg.edit({
- embeds: [pages[index]],
- components: [buttons],
- });
- await console.log(25)
- await mc.resetTimer();
- await console.log(26)
- }
- await console.log(27)
- mc.on(`end`, async () => {
- await console.log(28)
- await msg.edit({
- embeds: [pages[index]],
- components: [],
- });
- await console.log(29)
- })
- await console.log(30)
- return msg;
- })
- await console.log(31)
- } catch (e) {
- await console.log(32)
- await console.log(e)
- await console.log(33)
- }
- await console.log(34)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement