'Discord.js: Is there any possible way of disabling a menu after selecting one of it's options?

I've very recently had a look at buttons for my discord bots, and in doing so I also discovered the menus that you can create. I want to know how, if it's possible, to disable a menu after selecting one of it's options. The idea of the menu is you can choose from a selection of poems. Right now I only have 3 as I want to get this problem solved before I add more.

Here is the coding I have used:

const { MessageMenuOption, MessageMenu, MessageActionRow } = require("discord-buttons")

module.exports = {
    name: "poem",
    description: "Hear one of Natuski's poems!",
    async execute(client, message, args, Discord) {

        client.on('clickMenu', async (menu) => {
            if (menu.values[0] == 'ECF') {

                let ECFEmbed = new Discord.MessageEmbed()
                    .setTitle("Eagles Can Fly")
                    .setDescription("\nMonkeys can climb\nCrickets can leap\nHorses can race\nOwls can seek\nCheetahs can run\nEagles can fly\nPeople can try\nBut that's about it.")
                    .setColor('#FF8CC5')

                await menu.reply.defer();
                menu.channel.send(ECFEmbed);

            } else {

                if (menu.values[0] == 'ALS') {
                    let ALSEmbed = new Discord.MessageEmbed()
                        .setTitle("Amy Likes Spiders")
                        .setDescription("You know what I heard about Amy?\nAmy likes spiders.\nIcky, wriggly, hairy, ugly spiders!\nThat's why I'm not friends with her.\n\nAmy has a cute singing voice.\nI heard her singing my favorite love song.\nEvery time she sang the chorus, my heart would pound to the rhythm of the words.\nBut she likes spiders.\nThat's why I'm not friends with her.\n\nOne time, I hurt my leg really bad.\nAmy helped me up and took me to the nurse.\nI tried not to let her touch me.\nShe likes spiders, so her hands are probably gross.\nThat's why I'm not friends with her.\n\nAmy has a lot of friends.\nI always see her talking to people.\nShe probably talks about spiders.\nWhat if her friends start to like spiders too?\nThat's why I'm not friends with her.\n\nIt doesn't matter if she has other hobbies.\nIt doesn't matter if she keeps it private.\nIt doesn't matter if it doesn't hurt anyone.\n\nIt's gross.\nShe's gross.\nThe world is better off without spider lovers.\n\nAnd I'm gonna tell everyone.")
                        .setColor('#FF8CC5')

                    await menu.reply.defer();
                    menu.channel.send(ALSEmbed);

                } else {

                    if (menu.values[0] == 'BY') {
                        let BYEmbed = new Discord.MessageEmbed()
                            .setTitle("Because You")
                            .setDescription("Tomorrow will be brighter with me around\nBut when today is dim, I can only look down.\nMy looking is a little more forward\nBecause you look at me.\n\nWhen I want to say something, I say it with a shout!\nBut my truest feelings can never come out.\nMy words are a little less empty\nBecause you listen to me.\n\nWhen something is above me, I reach for the stars.\nBut when I feel small, I don't get very far.\nMy standing is a little bit taller\nBecause you sit with me.\n\nI believe in myself with all of my heart.\nBut what do I do when it's torn all apart?\nMy faith is a little bit stronger\nBecause you trusted me.\n\nMy pen always puts my feelings to the test.\nI'm not a good writer, but my best is my best.\nMy poems are a little bit dearer\nBecause you think of me.")
                            .setColor('#FF8CC5')

                        await menu.reply.d
                        await menu.reply.defer();
                        menu.channel.send(BYEmbed);
                    }
                }
            }
        });

        let poem1 = new MessageMenuOption()
            .setLabel('Eagles Can Fly')
            .setValue('ECF')
            .setDescription('')

        let poem2 = new MessageMenuOption()
            .setLabel('Amy Likes Spiders')
            .setValue('ALS')
            .setDescription('')

        let poem3 = new MessageMenuOption()
            .setLabel('Because You')
            .setValue('BY')
            .setDescription('')

        let poemMenu = new MessageMenu()
            .setID('Poem Menu')
            .setPlaceholder('Select Poem')
            .setMaxValues(1)
            .setMinValues(1)
            .addOption(poem1)
            .addOption(poem2)
            .addOption(poem3)

        let row = new MessageActionRow()
            .addComponent(poemMenu)

        await message.channel.send("A poem? O-Ok, which one would you like?", { components: [row] });
    }
}

The command works exactly as intended but as I would love to know what I need to add to make my request possible, if possible. Thanks!



Solution 1:[1]

First, we will be using the newest version of discord.js that includes buttons, slash commands and select menus, that is what you mean. So you won't need anymore discord-buttons.

We define the command. DO NOT define the event inside the command because the event will execute more times.

const { MessageMenuOption, MessageMenu, MessageActionRow } = require("discord-buttons")

const { MessageSelectMenu, MessageActionRow } = require("discord.js")

module.exports = {
    name: "poem",
    description: "Hear one of Natuski's poems!",
    async execute(client, message, args, Discord) {

        let selectMenu = new MessageSelectMenu()
        .addOptions([
            {
                label: "Eagles Can Fly",
                value: "EFC",
            },
            {
                label: "Amy Likes Spiders",
                value: "EFC"
            },
            {
                label: "Because You",
                value: "BY"
            }
        ])
        .setCustomId("PoemMenu") /* Do not use spaces when using IDs */
        .setPlaceholder("Select Poem")
        .setMinValues(1)
        .setMaxValues(1);
        
        let row = new MessageActionRow()
        .addComponents(selectMenu);

        await message.channel.send("A poem? O-Ok, which one would you like?", { components: [row] });
    }
}

And when defining the client create a new event:

client.on("interactionCreate", i => {
    const { MessageEmbed } = require("discord.js");

    if (i.isSelectMenu()) {
        if (menu.values[0] == 'ECF') {

            let ECFEmbed = new Discord.MessageEmbed()
                .setTitle("Eagles Can Fly")
                .setDescription("\nMonkeys can climb\nCrickets can leap\nHorses can race\nOwls can seek\nCheetahs can run\nEagles can fly\nPeople can try\nBut that's about it.")
                .setColor('#FF8CC5')

            await i.reply(EFCEmbed);

        } else {

            if (menu.values[0] == 'ALS') {
                let ALSEmbed = new Discord.MessageEmbed()
                    .setTitle("Amy Likes Spiders")
                    .setDescription("You know what I heard about Amy?\nAmy likes spiders.\nIcky, wriggly, hairy, ugly spiders!\nThat's why I'm not friends with her.\n\nAmy has a cute singing voice.\nI heard her singing my favorite love song.\nEvery time she sang the chorus, my heart would pound to the rhythm of the words.\nBut she likes spiders.\nThat's why I'm not friends with her.\n\nOne time, I hurt my leg really bad.\nAmy helped me up and took me to the nurse.\nI tried not to let her touch me.\nShe likes spiders, so her hands are probably gross.\nThat's why I'm not friends with her.\n\nAmy has a lot of friends.\nI always see her talking to people.\nShe probably talks about spiders.\nWhat if her friends start to like spiders too?\nThat's why I'm not friends with her.\n\nIt doesn't matter if she has other hobbies.\nIt doesn't matter if she keeps it private.\nIt doesn't matter if it doesn't hurt anyone.\n\nIt's gross.\nShe's gross.\nThe world is better off without spider lovers.\n\nAnd I'm gonna tell everyone.")
                    .setColor('#FF8CC5')

                await i.reply(ALSEmbed);

            } else {

                if (menu.values[0] == 'BY') {
                    let BYEmbed = new Discord.MessageEmbed()
                        .setTitle("Because You")
                        .setDescription("Tomorrow will be brighter with me around\nBut when today is dim, I can only look down.\nMy looking is a little more forward\nBecause you look at me.\n\nWhen I want to say something, I say it with a shout!\nBut my truest feelings can never come out.\nMy words are a little less empty\nBecause you listen to me.\n\nWhen something is above me, I reach for the stars.\nBut when I feel small, I don't get very far.\nMy standing is a little bit taller\nBecause you sit with me.\n\nI believe in myself with all of my heart.\nBut what do I do when it's torn all apart?\nMy faith is a little bit stronger\nBecause you trusted me.\n\nMy pen always puts my feelings to the test.\nI'm not a good writer, but my best is my best.\nMy poems are a little bit dearer\nBecause you think of me.")
                        .setColor('#FF8CC5')

                    await i.reply(BYEmbed);
                }
            }
        }
    })

Solution 2:[2]

just pass an empty array as the components when editing the message interaction.message.edit({components: []})

The interaction is the input for dclient.on('interactionCreate', interaction => ...)

Note: this will remove all components, so if you have buttons as well, you can disable them separately by assigning interaction.message.components into a variable then changing it (disabling them), then passing it back to the edit function

refer to the documentation for how to edit an imbedded message

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Krak798
Solution 2 Rstar37