Reputation: 393
I have this poll command that creates a new MessageEmbed, and then I want the bot to react to the votes with 4 emotes, to be able to vote in the poll. The problem is when I use the reply()
function with an interaction the bot crashes and gives me this error: DiscordAPIError: Interaction has already been acknowledged.
I tried to fetch the reply but it doesn't seem to work. Here's the code:
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:');
}
};
Thank you!
Upvotes: 1
Views: 34026
Reputation: 895
Just leaving this reply here for future reference, another issue that might cause DiscordAPIError: Interaction has already been acknowledged
is if you have two instances of your bot running simultaneously, for example on a remote server somewhere and on your local development server.
Upvotes: 31
Reputation: 1325
You forgot to await
your interaction.reply
.
It should be
message = await interaction.reply({ embeds: [pollEmbed], fetchReply: true });
Upvotes: 7