DiscordAPIError: Interaction has already been acknowledged. Discord.js react() function problem
DiscordAPIError: Interaction has already been acknowledged. Discord.js react() function problem
我有这个创建新 MessageEmbed 的投票命令,然后我希望机器人用 4 个表情对投票做出反应,以便能够在投票中投票。问题是当我使用 reply()
函数进行交互时,机器人崩溃并给我这个错误: DiscordAPIError: Interaction has already been acknowledged.
我试图获取回复,但它似乎不起作用。这是代码:
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('poll')
.setDescription('Make a poll, (and you get to choose the options) ;)')
.addStringOption((option) =>
option
.setName('title')
.setDescription('The title of the poll embed.')
.setRequired(true)
)
.addStringOption((option) =>
option
.setName('option1')
.setDescription('1st option for the poll.')
.setRequired(true)
)
.addStringOption((option) =>
option
.setName('option2')
.setDescription('2nd option for the poll.')
.setRequired(true)
)
.addStringOption((option) =>
option
.setName('option3')
.setDescription('3rd option for the poll.')
.setRequired(false)
)
.addStringOption((option) =>
option
.setName('option4')
.setDescription('4th option for the poll.')
.setRequired(false)
)
async execute(client, interaction, Discord) {
let pollEmbed;
if (interaction.options.get('option3') && interaction.options.get('option4')) {
pollEmbed = new Discord.MessageEmbed()
.setColor('RANDOM')
.setTitle(interaction.options.get('title').value)
.setAuthor(`Poll by: ${interaction.user.username}`)
.setDescription(
`:regional_indicator_a: - ${interaction.options.get('option1').value}\n
:regional_indicator_b: - ${interaction.options.get('option2').value}\n
:regional_indicator_c: - ${interaction.options.get('option3').value}\n
:regional_indicator_d: - ${interaction.options.get('option4').value}`
)
.setTimestamp();
}
if (!interaction.options.get('option3') && !interaction.options.get('option4')) {
pollEmbed = new Discord.MessageEmbed()
.setColor('RANDOM')
.setTitle(interaction.options.get('title').value)
.setAuthor(`Poll by: ${interaction.user.username}`)
.setDescription(
`:regional_indicator_a: - ${interaction.options.get('option1').value}\n
:regional_indicator_b: - ${interaction.options.get('option2').value}\n`
)
.setTimestamp();
}
if (interaction.options.get('option3') && !interaction.options.get('option4')) {
pollEmbed = new Discord.MessageEmbed()
.setColor('RANDOM')
.setTitle(interaction.options.get('title').value)
.setAuthor(`Poll by: ${interaction.user.username}`)
.setDescription(
`:regional_indicator_a: - ${interaction.options.get('option1').value}\n
:regional_indicator_b: - ${interaction.options.get('option2').value}\n
:regional_indicator_c: - ${interaction.options.get('option3').value}\n`
)
.setTimestamp();
}
if (!interaction.options.get('option3') && interaction.options.get('option4'))
return interaction.reply('You have to put option 3 before option 4!');
message = interaction.reply({ embeds: [pollEmbed], fetchReply: true });
await message.react(':regional_indicator_a:');
await message.react(':regional_indicator_b:');
await message.react(':regional_indicator_c:');
await message.react(':regional_indicator_d:');
}
};
谢谢!
您忘记了 await
您的 interaction.reply
。
应该是
message = await interaction.reply({ embeds: [pollEmbed], fetchReply: true });
只是将此回复留在此处以供将来参考,另一个可能导致 DiscordAPIError: Interaction has already been acknowledged
的问题是如果您同时有两个机器人实例 运行,例如在某处的远程服务器上和在您的本地开发服务器。
我有这个创建新 MessageEmbed 的投票命令,然后我希望机器人用 4 个表情对投票做出反应,以便能够在投票中投票。问题是当我使用 reply()
函数进行交互时,机器人崩溃并给我这个错误: DiscordAPIError: Interaction has already been acknowledged.
我试图获取回复,但它似乎不起作用。这是代码:
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('poll')
.setDescription('Make a poll, (and you get to choose the options) ;)')
.addStringOption((option) =>
option
.setName('title')
.setDescription('The title of the poll embed.')
.setRequired(true)
)
.addStringOption((option) =>
option
.setName('option1')
.setDescription('1st option for the poll.')
.setRequired(true)
)
.addStringOption((option) =>
option
.setName('option2')
.setDescription('2nd option for the poll.')
.setRequired(true)
)
.addStringOption((option) =>
option
.setName('option3')
.setDescription('3rd option for the poll.')
.setRequired(false)
)
.addStringOption((option) =>
option
.setName('option4')
.setDescription('4th option for the poll.')
.setRequired(false)
)
async execute(client, interaction, Discord) {
let pollEmbed;
if (interaction.options.get('option3') && interaction.options.get('option4')) {
pollEmbed = new Discord.MessageEmbed()
.setColor('RANDOM')
.setTitle(interaction.options.get('title').value)
.setAuthor(`Poll by: ${interaction.user.username}`)
.setDescription(
`:regional_indicator_a: - ${interaction.options.get('option1').value}\n
:regional_indicator_b: - ${interaction.options.get('option2').value}\n
:regional_indicator_c: - ${interaction.options.get('option3').value}\n
:regional_indicator_d: - ${interaction.options.get('option4').value}`
)
.setTimestamp();
}
if (!interaction.options.get('option3') && !interaction.options.get('option4')) {
pollEmbed = new Discord.MessageEmbed()
.setColor('RANDOM')
.setTitle(interaction.options.get('title').value)
.setAuthor(`Poll by: ${interaction.user.username}`)
.setDescription(
`:regional_indicator_a: - ${interaction.options.get('option1').value}\n
:regional_indicator_b: - ${interaction.options.get('option2').value}\n`
)
.setTimestamp();
}
if (interaction.options.get('option3') && !interaction.options.get('option4')) {
pollEmbed = new Discord.MessageEmbed()
.setColor('RANDOM')
.setTitle(interaction.options.get('title').value)
.setAuthor(`Poll by: ${interaction.user.username}`)
.setDescription(
`:regional_indicator_a: - ${interaction.options.get('option1').value}\n
:regional_indicator_b: - ${interaction.options.get('option2').value}\n
:regional_indicator_c: - ${interaction.options.get('option3').value}\n`
)
.setTimestamp();
}
if (!interaction.options.get('option3') && interaction.options.get('option4'))
return interaction.reply('You have to put option 3 before option 4!');
message = interaction.reply({ embeds: [pollEmbed], fetchReply: true });
await message.react(':regional_indicator_a:');
await message.react(':regional_indicator_b:');
await message.react(':regional_indicator_c:');
await message.react(':regional_indicator_d:');
}
};
谢谢!
您忘记了 await
您的 interaction.reply
。
应该是
message = await interaction.reply({ embeds: [pollEmbed], fetchReply: true });
只是将此回复留在此处以供将来参考,另一个可能导致 DiscordAPIError: Interaction has already been acknowledged
的问题是如果您同时有两个机器人实例 运行,例如在某处的远程服务器上和在您的本地开发服务器。