189
rated 0 times
[
196]
[
7]
/ answers: 1 / hits: 23965
/ 2 Years ago, tue, february 15, 2022, 12:00:00
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!
More From » discord