Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
How to set select menu in individual file discord.js

I am making a Discord bot in discord.js and set the slash commands up in individual files, so I don't get lost in the code.

But one of those commands has a select menu in it, but since select menu's are an interaction on their own, it does not know what file to look for to find it's execution.

I use the following code to detect commands

client.on('interactionCreate', async interaction => {
    if (!interaction.isCommand()) return;

    const command = client.commands.get(interaction.commandName);

    if (!command) return;

    try {
        await command.execute(interaction);
    } catch (error) {
        console.error(error);
        await interaction.reply({ content: 'Hmm, we appear to have run into an error. Please try again in a few minutes, if this error persists, please let us know!', ephemeral: true });
    }
});

You could do the same for select menu's

client.on('interactionCreate', async interaction => {
    if (!interaction.isSelectMenu()) return;

    if (interaction.customId === 'helpMenu') {
        await interaction.update('Worked!');
    }
});

But since my commands are in their own folders, this does not work.

I tried moving the code of responding to the interaction to my main file, but it does not recognize the customId, because the select menu is not defined in that file.

How am I supposed to do this? Or am I missing something really obvious?

Thanks in advance,

cheers

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

One way you could do this would be to pass the client made in the main.js file as an argument to the command file where you created the MessageSelectMenu. Then, you could then create an event listener for any click on the MessageSelectMenu. But you would have to check whether the user id was the same as the one who ran the slash command and also check if the guild id was the same. An example is this:

interaction.reply({ components: [row] }); // Send the MessageSelectMenu
client.on("interactionCreate", (click) => {
  if (
    click.user.id !== interaction.user.id || // Check if the user who clicked the MessageSelectMenu was the same as the one who ran the slash command
    click.guildId !== interaction.guildId || // Check if the guild id where the user clicked the MessageSelectMenu was the same as the one where the slash command was run 
    !click.isSelectMenu() // Check if the interaction was a MessageSelectMenu click
  )
    return;
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!