Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

352
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda