提问者:小点点

DiscordAPIError:交互已经被确认。Discord.js反应()函数问题


我有这个投票命令,它创建了一个新的MessageEmbed,然后我希望机器人用4个表情对投票做出反应,以便能够在投票中投票。问题是当我使用回复()函数进行交互时,机器人崩溃并给我这个错误:DiscordAPIError:交互已经被确认。我试图获取回复,但似乎不起作用。代码如下:

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:');
    }
};

非常感谢。


共2个答案

匿名用户

把这个回复留在这里供将来参考,另一个可能导致不一致错误的问题是:交互已经被确认,如果你有两个机器人实例同时运行,例如在某处的远程服务器和本地开发服务器上。

匿名用户

你忘了等待你的互动。回复。

应该是这样的

message = await interaction.reply({ embeds: [pollEmbed], fetchReply: true });