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

145
Vistas
Receiving discord.js slash command parameters

I'm currently trying to make a calculation using parameters input via a slash command. Putting them in works fine, however I do not know how to actually retrieve them. the current code yields an error TypeError: Cannot read properties of undefined (reading 'get') which has me quite confused, as the discord.js documentation shows that said function should exist and be exactly what I'm looking for.

const { SlashCommandBuilder } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('manacost')
        .setDescription('Calculates the ´soul spawn cost using your inputs')
        .addStringOption(option =>
            option.setName('health')
                .setDescription('The amount of health your soul has. Supports k=1000...')
                .setRequired(true))
        .addStringOption(option =>
            option.setName('damage')
                .setDescription('The amount of damage your soul has. Supports k=1000...')
                .setRequired(true))
        .addIntegerOption(option =>
            option.setName('breeze')
                .setDescription('The amount of breeze you have.(0-80)')
                .setRequired(false)),
    async execute(interaction) {
        if (!interaction.isChatInputCommand()) return;
        let hp = interaction.options.get('health');
        let dmg = interaction.option.get('damage');
        let b =  interaction.option.get('breeze');
        console.log({hp, dmg, b});
        await interaction.reply({content: hp, dmg, b});
    },
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The interaction options can be found using interaction.option.getString() or interaction.option.getInteger(). Also in your Code you have mixed up interaction.options and interaction.option. You should only use interaction.options.

That means your code has to change from

let hp = interaction.options.get('health');
let dmg = interaction.option.get('damage');
let b =  interaction.option.get('breeze');

to

let hp = interaction.options.getString('health');
let dmg = interaction.options.getString('damage');
let b =  interaction.options.getInteger('breeze');

You should take a look at this post from the discord.js guide for more information and a look at the other option types.

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