'Discord.js (v13) - Edit a message using a dropdown menu

I would like to make a dropdown menu that edits its own "parent" message. (The message is a response to a slash command interaction) My code now looks like this:

const row = new MessageActionRow()
    .addComponents(
        new MessageSelectMenu()
            .setCustomId('row')
            .setPlaceholder('Letter')
            .addOptions([
                {
                    label: 'A',
                    value: 'A',
                },
                {
                     label: 'B',
                     value: 'B',
                },
                {
                    label: 'C',
                    value: 'C',
                },
                {
                    label: 'D',
                    value: 'D',
                },
            ]),
    ); // End of .addComponents()
interaction.reply({content: "Select a letter!", components: [row]})

client.on("interactionCreate", async menuInteraction => {
    if (!menuInteraction.isSelectMenu()) return;
                        
    switch (menuInteraction.values[0]) {
        case "A":  
            interaction.editReply("A")
            break;
        case "B":  
            interaction.editReply("B")
            break;
        case "C": 
            interaction.editReply("C")
            break;
        case "D":
            interaction.editReply("D")
            break;
    };                
});

The code works fine. However, I found a bug that I can't fix. When I summon the slash command more than once and I select an option in the last message's dropdown menu, both messages gets edited.

Is there any way to fix that? I guess I should check if the slash command's reply message id is the same as the dropdown menu interaction's message id somehow, but I have no idea how to get the slash command's reply message. As I know the client.user.lastMessage() got removed in v13 so I can't use that.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source