Actualmente estoy tratando de hacer un cálculo utilizando la entrada de parámetros a través de un comando de barra inclinada. Ponerlos funciona bien, sin embargo, no sé cómo recuperarlos. el código actual produce un error TypeError: Cannot read properties of undefined (reading 'get') lo que me tiene bastante confundido, ya que la documentación de discord.js muestra que dicha función debería existir y ser exactamente lo que estoy buscando.
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}); }, }Las opciones de interacción se pueden encontrar mediante interaction.option.getString() o interaction.option.getInteger() . También en su Código ha mezclado interaction.options e interaction.option . Solo debe usar las opciones de interaction.options .
Eso significa que su código tiene que cambiar de
let hp = interaction.options.get('health'); let dmg = interaction.option.get('damage'); let b = interaction.option.get('breeze');a
let hp = interaction.options.getString('health'); let dmg = interaction.options.getString('damage'); let b = interaction.options.getInteger('breeze');Debería echar un vistazo a esta publicación de la guía discord.js para obtener más información y ver los otros tipos de opciones.