I am currently working on a calculation that involves using parameters input through a slash command. While entering the parameters works without any issues, I am facing difficulty in retrieving them. The current code is resulting in an error
TypeError: Cannot read properties of undefined (reading 'get')
, which is confusing as the discord.js documentation clearly indicates that the function in question should exist and serve my purpose.
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('manacost')
.setDescription('Calculates the soul spawn cost based on 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});
},
}