互动已确认
Interaction has already been acknowledged
我目前的 /help 命令有问题,我的 /help 命令的工作方式是发送一个漂亮的花式嵌入 select 菜单,您可以 select 不同的页面。一切正常,当我执行 /help 并获取嵌入然后再次执行 /help 并与第二个嵌入交互时,问题就来了,它会崩溃并给出错误“交互已经被确认”这是我的代码。
const generalHelp = { // Creates generalHelp embed.
color: 0x901ab6,
title: 'join our support server!',
url: 'https://discord.gg/MUwJ85wpKP',
author: {
name: 'Help Menu',
icon_url: 'https://cdn.discordapp.com/attachments/937276227692150815/937552170520301588/Letter_Z.png',
},
description: 'Select an option to view the commands I have!',
fields: [
{
name: ':tada: Fun Commands',
value: 'Shows all the bots varying fun commands in a nice little page for easy viewing.',
inline: true,
},
{
name: ':tools: Admin Commands',
value: 'Shows all the bots varying admin commands in a nice little page for easy viewing.',
inline: true,
},
/*{
name: '\u200b',
value: ' \u200b ',
inline: false,
},*/
],
}
const adminHelp = { // Creates moderationHelp embed.
color: 0x901ab6,
author: {
name: 'Help Menu',
icon_url: 'https://cdn.discordapp.com/attachments/937276227692150815/937552170520301588/Letter_Z.png',
},
description: 'Here are the commands!',
fields: [
{
name: 'Prefix: `/`',
value: '\u200b',
},
{
name: ':tools: Admin Commands',
value: '`toggle`, `settings`'
},
]
}
const funHelp = { // Creates funHelp embed.
color: 0x901ab6,
author: {
name: 'Help Menu',
icon_url: 'https://cdn.discordapp.com/attachments/937276227692150815/937552170520301588/Letter_Z.png',
},
description: 'Here are the commands!',
fields: [
{
name: 'Prefix: `/`',
value: '\u200b',
},
{
name: ':tada: Fun Commands',
value: '`ping`, `poll`',
},
]
}
const row = new MessageActionRow() // Creates MessageActionRow with name row.
.addComponents(
new MessageSelectMenu()
.setCustomId('select')
.setPlaceholder('Select an option')
.addOptions([
{
label: ' Fun Commands',
description: '',
value: 'first_option',
},
{
label: ' Admin Commands',
description: '',
value: 'second_option',
},
])
)
await interaction.reply({ embeds: [generalHelp], components: [row]}) // Displays general help embed
这是我处理交互的代码。
interaction.client.on('interactionCreate', interaction => { // Detects which value is selected.
if(!interaction.isSelectMenu()) return
if (interaction.values[0] === 'first_option') // Checks if values[0] is = to first_option to display gameHelp embed.
{
interaction.update({embeds: [funHelp]}) // Updates bots interaction embed
}
if (interaction.values[0] === 'second_option') // Checks if values[0] is = to second_option to display musicHelp embed.
{
interaction.update({embeds: [adminHelp]}) // Updates bots interaction embed
}
else // If values[0] is anything else display error message to console. (PM2 will auto restart bot if error happens.)
{
return//console.log('Help Menu Select Menu Error!') // Logging to PM2 console.
}
})
如果有人能帮我解决问题就太好了<3
因为您已经.reply()
-ed 进行了交互,所以交互已经被确认。
要解决此问题,您可以使用 .editReply()
:
interaction.reply({ content: 'This is my first reply!' });
interaction.editReply({ content: 'This my edited second reply!' });
对于仍在寻找答案的任何人,发生这种情况的原因是因为它第一次工作 100% 正常,因为没有更新并且是全新的交互。但是,当您尝试更新它时,这也算作一次交互。将您的 interactionCreate 代码放入事件处理程序中可以解决此问题。
module.exports = {
name: 'interactionCreate',
execute(interaction) {
//console.log(`${interaction.user.tag} in #${interaction.channel.name} triggered an interaction.`);
if (!interaction.isSelectMenu() && interaction.isCommand()) return
if (interaction.customId !== 'select') return
switch (interaction.values[0]) {
case 'first_option':
interaction.update({embeds: [funHelp], ephemeral: true})
break
case 'second_option':
interaction.update({embeds: [adminHelp], ephemeral: true})
break
default:
return
}
},
};
我目前的 /help 命令有问题,我的 /help 命令的工作方式是发送一个漂亮的花式嵌入 select 菜单,您可以 select 不同的页面。一切正常,当我执行 /help 并获取嵌入然后再次执行 /help 并与第二个嵌入交互时,问题就来了,它会崩溃并给出错误“交互已经被确认”这是我的代码。
const generalHelp = { // Creates generalHelp embed.
color: 0x901ab6,
title: 'join our support server!',
url: 'https://discord.gg/MUwJ85wpKP',
author: {
name: 'Help Menu',
icon_url: 'https://cdn.discordapp.com/attachments/937276227692150815/937552170520301588/Letter_Z.png',
},
description: 'Select an option to view the commands I have!',
fields: [
{
name: ':tada: Fun Commands',
value: 'Shows all the bots varying fun commands in a nice little page for easy viewing.',
inline: true,
},
{
name: ':tools: Admin Commands',
value: 'Shows all the bots varying admin commands in a nice little page for easy viewing.',
inline: true,
},
/*{
name: '\u200b',
value: ' \u200b ',
inline: false,
},*/
],
}
const adminHelp = { // Creates moderationHelp embed.
color: 0x901ab6,
author: {
name: 'Help Menu',
icon_url: 'https://cdn.discordapp.com/attachments/937276227692150815/937552170520301588/Letter_Z.png',
},
description: 'Here are the commands!',
fields: [
{
name: 'Prefix: `/`',
value: '\u200b',
},
{
name: ':tools: Admin Commands',
value: '`toggle`, `settings`'
},
]
}
const funHelp = { // Creates funHelp embed.
color: 0x901ab6,
author: {
name: 'Help Menu',
icon_url: 'https://cdn.discordapp.com/attachments/937276227692150815/937552170520301588/Letter_Z.png',
},
description: 'Here are the commands!',
fields: [
{
name: 'Prefix: `/`',
value: '\u200b',
},
{
name: ':tada: Fun Commands',
value: '`ping`, `poll`',
},
]
}
const row = new MessageActionRow() // Creates MessageActionRow with name row.
.addComponents(
new MessageSelectMenu()
.setCustomId('select')
.setPlaceholder('Select an option')
.addOptions([
{
label: ' Fun Commands',
description: '',
value: 'first_option',
},
{
label: ' Admin Commands',
description: '',
value: 'second_option',
},
])
)
await interaction.reply({ embeds: [generalHelp], components: [row]}) // Displays general help embed
这是我处理交互的代码。
interaction.client.on('interactionCreate', interaction => { // Detects which value is selected.
if(!interaction.isSelectMenu()) return
if (interaction.values[0] === 'first_option') // Checks if values[0] is = to first_option to display gameHelp embed.
{
interaction.update({embeds: [funHelp]}) // Updates bots interaction embed
}
if (interaction.values[0] === 'second_option') // Checks if values[0] is = to second_option to display musicHelp embed.
{
interaction.update({embeds: [adminHelp]}) // Updates bots interaction embed
}
else // If values[0] is anything else display error message to console. (PM2 will auto restart bot if error happens.)
{
return//console.log('Help Menu Select Menu Error!') // Logging to PM2 console.
}
})
如果有人能帮我解决问题就太好了<3
因为您已经.reply()
-ed 进行了交互,所以交互已经被确认。
要解决此问题,您可以使用 .editReply()
:
interaction.reply({ content: 'This is my first reply!' });
interaction.editReply({ content: 'This my edited second reply!' });
对于仍在寻找答案的任何人,发生这种情况的原因是因为它第一次工作 100% 正常,因为没有更新并且是全新的交互。但是,当您尝试更新它时,这也算作一次交互。将您的 interactionCreate 代码放入事件处理程序中可以解决此问题。
module.exports = {
name: 'interactionCreate',
execute(interaction) {
//console.log(`${interaction.user.tag} in #${interaction.channel.name} triggered an interaction.`);
if (!interaction.isSelectMenu() && interaction.isCommand()) return
if (interaction.customId !== 'select') return
switch (interaction.values[0]) {
case 'first_option':
interaction.update({embeds: [funHelp], ephemeral: true})
break
case 'second_option':
interaction.update({embeds: [adminHelp], ephemeral: true})
break
default:
return
}
},
};