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

351
Views
Discord.JS how would I add a text based user input parameter?

My code for a command called ping looks like this:

const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('ping')
        .setDescription('Replies with Pong!'),

    options: [
        {
            name: 'message',
            description: 'Replies with your message!',
            type: 'string',
            required: false,
            default: 'Pong!'
        }
    ],
    async execute(interaction, args) {
        const [ message ] = args;
        return interaction.reply(ping);
    },
};

And currently, when I run this command (and deploy the slash commands first), there is no user enterable parameter, and it throws an error.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

ik i answering too late, but you can create variable and use it to get content from the input:

const message = interaction.options.getString('message')

getString('message') instead of the message inside brackets you can put whatever the name of the option or command is.

for example:

.addStringOption(option =>
            option 
                .setName('off')
                .setDescription('anti-spam is off')
        )

now i need to get this 'off' inside option, so easy,

const SpamOn = interaction.options.getString('off')
about 4 years ago · Juan Pablo Isaza Report

0

In order to access that parameter in a slash command, the user must be able to enter a parameter, so when you register the command, you must indicate how many parameters you want to receive and what type.

Documentation on how to add parameters to the commands here.

Documentation on how to read the arguments of a user-entered command here enter link description here.

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!