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

255
Views
Cómo configurar el menú de selección en un archivo individual discord.js

Estoy creando un bot de Discord en discord.js y configuro los comandos de barra en archivos individuales, para no perderme en el código.

Pero uno de esos comandos tiene un menú de selección, pero dado que los menús de selección son una interacción en sí mismos, no sabe qué archivo buscar para encontrar su ejecución.

Yo uso el siguiente código para detectar comandos

 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 }); } });

Podrías hacer lo mismo para seleccionar el menú

 client.on('interactionCreate', async interaction => { if (!interaction.isSelectMenu()) return; if (interaction.customId === 'helpMenu') { await interaction.update('Worked!'); } });

Pero como mis comandos están en sus propias carpetas, esto no funciona.

Intenté mover el código de respuesta a la interacción a mi archivo principal, pero no reconoce el customId, porque el menú de selección no está definido en ese archivo.

¿Cómo se supone que debo hacer esto? ¿O me estoy perdiendo algo realmente obvio?

Gracias por adelantado,

salud

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

0

Una forma de hacerlo sería pasar el cliente creado en el archivo main.js como argumento al archivo de comando donde creó MessageSelectMenu . Luego, podría crear un detector de eventos para cualquier clic en MessageSelectMenu . Pero tendría que verificar si la identificación del usuario era la misma que la que ejecutó el comando de barra oblicua y también verificar si la identificación del gremio era la misma. Un ejemplo es este:

 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!