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

143
Views
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 answers
Answer question

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 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!