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

357
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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