Проблема с пагинатором в Discord.Js

Рейтинг: 0Ответов: 1Опубликовано: 06.07.2023

const { ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType, StringSelectMenuBuilder, StringSelectMenuOptionBuilder } = require('discord.js');
const { execute } = require('../../../Events/interaction/settings.js');

async function buttonPages(interaction, pages) {

    const prev = new ButtonBuilder()
        .setCustomId("prev")
        .setEmoji("◀")
        .setStyle(ButtonStyle.Primary)
        .setDisabled(true);

    const home = new ButtonBuilder()
        .setCustomId('home')
        .setEmoji("🏡")
        .setStyle(ButtonStyle.Secondary)
        .setDisabled(true);

        const refresh = new ButtonBuilder()
        .setCustomId("refresh")
        .setEmoji("🔁")
        .setStyle(ButtonStyle.Secondary);

    const settings = new ButtonBuilder()
        .setCustomId('settings')
        .setEmoji("⚙")
        .setStyle(ButtonStyle.Secondary);

    const next = new ButtonBuilder()
        .setCustomId("next")
        .setEmoji("▶")
        .setStyle(ButtonStyle.Primary);

    const buttonRow = new ActionRowBuilder().addComponents(prev, home, refresh, settings, next)
    let index = 0;

    const currentPage = await interaction.update({
        embeds: [pages[index]],
        components: [buttonRow],
    });

    const collector = await currentPage.createMessageComponentCollector({
        componentType: ComponentType.Button,
    });

    collector.on("collect", async (i) => {
        if (i.user.id !== interaction.user.id)
            return i.reply({
                content: "You can't use these buttons",
                emphemeral: true,
            });

        if (i.customId === "prev") {
            if (index > 0) index--;
        } else if (i.customId === "home") {
            index = 0;
        } else if (i.customId === "next") {
            if (index < pages.length - 1) index++;
        } else if (i.customId === "settings") {
            await i.reply({
                embeds: [
                {
                тут обычный эмбед при появлении селект меню
                }
               ],
                components: [
                    new ActionRowBuilder()
                    .addComponents(
                    само селект меню с настройками
                    )
                   ],
                                  fetchReply: true
            })
        } else if (i.customId === "refresh") {

        }
    
        if (index === 0) prev.setDisabled(true);
        else prev.setDisabled(false);
    
        if (index === 0) home.setDisabled(true);
        else home.setDisabled(false);
    
        if (index === pages.length - 1) next.setDisabled(true);
        else next.setDisabled(false);

        await i.update({
            embeds: [pages[index]],
            components: [buttonRow],
            fetchReply: true
        });
    })
}

module.exports = buttonPages;

У меня имеется пагинатор, в котором присутствует 5 кнопок.

  1. Кнопка назад.
  2. Кнопка домой. (с любой страницы перекидывает на 1)
  3. Кнопка обновить. (обновляет данные на странице)
  4. Кнопка настройки. (перекидывает на селект меню, которое позволяет менять значения на странице)
  5. Кнопка вперед.

В чём же проблема? При вводе команды /settings у меня появляется меню конфигурации, где выводится какая-то информация. При нажатии на кнопку "Настройка конфигурации" появляется меню с страничками и пагинатором. Сами кнопки работают, но вот при нажатии на кнопку настройки у меня выводится селект меню и выкидвается ошибка в консоль Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred. Так же я немного не понимаю, как мне сделать 3-ую кнопку, потому что при использовании interaction.update({}) ничего не происходит.

Ответы

▲ 0Принят

Я нашёл! Чтобы пропала ошибка нужно было заменить await i.reply на return i.reply, а кнопка обновления делалась обычным обновлением страниц