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

279
Vistas
Parse Arguments from Discord interactions

I am currently coding a discord bot and wanted to play around with the new interaction feature (aka slash-commands).

I managed to get a "/test" Interaction working, and the bot receives the command and executes my code for it (following discord.js manual). Now I know from interaction.commandName what name for example the command has (in this case "test"), but I don’t seem to be able to get the arguments that are passed in.

Following is my "test.js", which is for the "/test" command:

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

The command itself gets called by a function that is also from the documentation of 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 });
    }
});

I looked through the documentation and searched quite a bit online, but I don’t seem to find anything. If anyone could help me that would be great.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Warning: I did not test this code CommandInteractions have an options property. You can use the get method on it.

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

.value shows the input as shown here. It can be empty if there is no input (option was not required and user did not input that option)

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