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

289
Views
Analizar argumentos de las interacciones de Discord

Actualmente estoy codificando un bot de discordia y quería jugar con la nueva función de interacción (también conocida como comandos de barra oblicua).

Logré hacer funcionar una interacción "/test", y el bot recibe el comando y ejecuta mi código (siguiendo el manual de discord.js). Ahora sé por interaction.commandName qué nombre tiene, por ejemplo, el comando (en este caso, "prueba"), pero parece que no puedo obtener los argumentos que se pasan.

El siguiente es mi "test.js", que es para el comando "/test":

 const { SlashCommandBuilder } = require('@discordjs/builders'); module.exports = { data: new SlashCommandBuilder() .setName('test') .setDescription('Test with arguments!') .addStringOption(option => option.setName("device") .setDescription("Some argument") .setRequired(true) .addChoice("Arg A", "A") .addChoice("Arg B", "B") ), async execute(interaction, log) { // log is a function to log to a file... // Ignore it, since it is not *currently* in use. return interaction.reply("You selected the argument ????") // Delete message after 5 seconds .then(setTimeout(() => interaction.deleteReply(), 5000)); }, };

El comando en sí es llamado por una función que también proviene de la documentación de discord.js:

 client.on('interactionCreate', async(interaction) => { if (!interaction.isCommand()) return; const command = client.commands.get(interaction.commandName); if (!command) return; try { await command.execute(interaction, log); } catch (error) { console.error(error); await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); } });

Revisé la documentación y busqué un poco en línea, pero parece que no encuentro nada. Sería genial si alguien pudiese ayudarme.

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

0

Advertencia: no probé este código CommandInteraction s tiene una propiedad de options . Puedes usar el método get en él.

 //the option name is 'TEST' and the user inputted 'hey' let option = interaction.options.get("TEST") console.log(option.value)

.value muestra la entrada como se muestra aquí . Puede estar vacío si no hay entrada (no se requirió la opción y el usuario no ingresó esa opción)

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!