Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

250
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda