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