DiscordAPIError: Interaction has already been acknowledged.
run: async (client, interaction) => {
let choice1Answer = null
let choice2Answer = null
let accepted = true
let target = interaction.options.getUser('target');
const user = interaction.member
const embed = new Discord.MessageEmbed()
.setColor(client.config.embedColor)
.setTitle('Камень, Ножницы, Бумага')
.setDescription(`${interaction.member} приглашает ${target} в игру "Камень, Ножницы, Бумага"`)
const acceptRow = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setCustomId('rsp-accept')
.setLabel('Принять')
.setStyle('SUCCESS'),
new Discord.MessageButton()
.setCustomId('rsp-cancel')
.setLabel('Отказаться')
.setStyle('DANGER'),
);
msg = await interaction.reply({
content: `${target}`,
embeds: [embed],
components: [acceptRow]
})//.then(interaction => msgId = interaction.reply.id);
const msgId = await interaction.fetchReply()
const collector = interaction.channel.createMessageComponentCollector({
time: 1 * 1000 * 60,
});
collector.on('collect', interaction => {
if (interaction.customId === 'rsp-accept') {
if (interaction.member.id !== target.id) return interaction.deferUpdate()
const choice1 = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageSelectMenu()
.setCustomId('choice1')
.setPlaceholder('Выберите свой ход')
.addOptions([{
label: 'Камень',
value: 'Камень',
},
{
label: 'Ножницы',
value: 'Ножницы',
},
{
label: 'Бумага',
value: 'Бумага',
},
]),
);
interaction.reply({ components: [choice1], ephemeral: true }).catch(() => {})
} else if (interaction.customId === 'choice1') {
choice1Answer = interaction.values[0]
const userRow = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setCustomId('user-select')
.setLabel('Сделать ход')
.setStyle('PRIMARY'),
);
interaction.deferUpdate()
msgId.edit({ content: `**Пользователь ${target} сделал свой ход. ${user}, сделайте свой ход.**`, components: [userRow], embeds: [ ] }).catch(() => {})
} else if (interaction.customId === 'user-select') {
if (user.id !== interaction.member.id) return interaction.deferUpdate()
const choice2 = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageSelectMenu()
.setCustomId('choice2')
.setPlaceholder('Выберите свой ход')
.addOptions([{
label: 'Камень',
value: 'Камень',
},
{
label: 'Ножницы',
value: 'Ножницы',
},
{
label: 'Бумага',
value: 'Бумага',
},
]),
);
interaction.reply({ components: [choice2], ephemeral: true }).catch(() => {})
} else if (interaction.customId === 'choice2') {
choice2Answer = interaction.values[0]
interaction.deferUpdate()
const embedResult = new Discord.MessageEmbed()
.setColor(client.config.embedColor)
if (choice1Answer == choice2Answer) {
embedResult.setTitle('Ничья!')
}
else if (choice1Answer == "Камень") {
if (choice2Answer == "Бумага") {
embedResult.setTitle(`Выиграл пользователь ${user.displayName}!`)
}
if (choice2Answer == "Ножницы") {
embedResult.setTitle(`Выиграл пользователь ${target.username}!`)
}
}
else if (choice1Answer == "Бумага") {
if (choice2Answer == "Ножницы") {
embedResult.setTitle(`Выиграл пользователь ${user.displayName}!`)
}
if (choice2Answer == "Камень") {
embedResult.setTitle(`Выиграл пользователь ${target.username}!`)
}
}
else if (choice1Answer == "Ножницы") {
if (choice2Answer == "Камень") {
embedResult.setTitle(`Выиграл пользователь ${user.displayName}!`)
}
if (choice2Answer == "Бумага") {
embedResult.setTitle(`Выиграл пользователь ${target.username}!`)
}
}
accepted = false
embedResult.setDescription(`Выбор ${target} — ${choice1Answer} | Выбор ${user} — ${choice2Answer}`)
msgId.edit({ embeds: [embedResult], content: ' ', components: [ ] }).catch(() => {})
collector.stop();
}
});
collector.on('end', (interaction, error) => {
if (accepted) msgId.edit({ embeds: [ ], content: `${client.emotes.error} \`${target.username}\` не ответил на Ваше предложение.`, components: [ ] }).catch(() => {})
});
}