编辑回复的消息组件重新发送交互,如何停止?

Editing a reply's message components resends an interaction, how do I stop it?

我制作了一个机器人命令

  1. 回复 select 菜单
  2. 等待select离子生成
  3. 编辑回复以使用按钮而不是 select 菜单
  4. 等待按下按钮
  5. 再次编辑回复

但是,每当我像这样编辑回复的消息组件时,它会起作用,在编辑之后,机器人会立即收到一个新的交互,它不会去任何地方。 结果是新组件的行为就像被按下一样,给我加载符号,直到交互失败。然后组件工作正常,只剩下红色的“应用程序没有响应”文本。 对于用户来说,这当然相当烦人,而且令人困惑和丑陋。所以我希望有人能告诉我是否可以做任何事情,如果可以的话具体是什么。

这是一个非常简单的示例命令,演示了这种行为:

client.on('interactionCreate', async interaction => {
    console.log('interaction received');
    
    const { commandName } = interaction;
    if (commandName === 'test') {
        const select = new MessageActionRow().addComponents(
            new MessageSelectMenu().setCustomId('select').setPlaceholder(`Select a match to tip on.`)
            .addOptions([ {label: `select me`,  value: `testValue`} ])
        )
        await interaction.reply({ content: 'Please make a selection', components: [select], ephemeral: true });

        const collectedSelect = await interaction.channel?.awaitMessageComponent({ componentType: 'SELECT_MENU'})
        console.log(collectedSelect.values[0]);

        const button = new MessageActionRow().addComponents(
            new MessageButton().setCustomId(`button`).setLabel('push me').setStyle('PRIMARY')
        )
        await interaction.editReply({ content: 'Thanks for making a selection. Now, please push the button.', components: [button], ephemeral: true });

        const collectedButton = await interaction.channel?.awaitMessageComponent({ componentType: 'BUTTON'})
        console.log(collectedButton.customId);

        return interaction.editReply({ content: 'Thanks for pushing the button.', components: [], ephemeral: true });
    }
}

哦,好吧。我正在寻找其他东西,发现这个小家伙解决了我的问题:update()

它只需要 运行 在使用 .awaitMessageComponent() 收集的交互上,而不是原始交互(就像在我的操作中)。 看起来像这样:

const select = new MessageActionRow().addComponents(
     new MessageSelectMenu().setCustomId('select').setPlaceholder(`Select a match to tip on.`)
     .addOptions([ {label: `select me`,  value: `testValue`} ])
)
await interaction.reply({ content: 'Please make a selection', components: [select], ephemeral: true });

const collectedSelect = await interaction.channel?.awaitMessageComponent({ componentType: 'SELECT_MENU'})
console.log(collectedSelect.values[0]);

const button = new MessageActionRow().addComponents(
     new MessageButton().setCustomId(`button`).setLabel('push me').setStyle('PRIMARY')
)
await collectedSelect.update({ content: 'Thanks for making a selection. Now, please push the button.', components: [button], ephemeral: true });

const collectedButton = await interaction.channel?.awaitMessageComponent({ componentType: 'BUTTON'})
console.log(collectedButton.customId);

return collectedButton.update({ content: 'Thanks for pushing the button.', components: [], ephemeral: true });

老实说,我不知道为什么 .editReply() 还行不通,但不管我怎么猜。