cla*_*iew 1 javascript discord discord.js
我有一个创建新 MessageEmbed 的 poll 命令,然后我希望机器人用 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:');
}
};
Run Code Online (Sandbox Code Playgroud)
谢谢你!
dec*_*cho 29
只是将此回复留在这里以供将来参考,可能导致的另一个问题DiscordAPIError: Interaction has already been acknowledged是,如果您的机器人实例同时运行,例如在某处的远程服务器上和本地开发服务器上。
你忘了await你的interaction.reply.
它应该是
message = await interaction.reply({ embeds: [pollEmbed], fetchReply: true });
Run Code Online (Sandbox Code Playgroud)