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

241
Visualizações
Discord.js (v13) SlashCommandBuilder addIntegerOption set Range

I want to write a slash command that clears messages. Everything is fine, but there one thing I couldn't really figure out:

How would I set the range for an integer option in a slash command build, or is there even something like this or do I need to do the old-school way and response that the value is out of range?

Here is my data for the slash command that will be registered:

data: new SlashCommandBuilder()
        .setName('clear')
        .setDescription('Clears specified amount of Messages')
        .addIntegerOption(option => {
            option
            .setName('amount')
            .setRequired(true)
            .setDescription('The Amount of Messages to clear')
        }),
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Sadly there Is no option to set the range, but there a new thing called ephemeral that you can use as a setting in interaction.reply()

example:

interaction.reply({ content: "Your amount is bigger than 500", ephemeral: true"})

result

ephemeral lets only the user of the command see the reply and he can simply delete it if he wants through pressing the blue text wich says "Nachricht verferfen" in my case because my Discord is set to German.

Edit I have to correct Myself there is actually an Option for min and max for integer options and for some other options like string options you actually can write your own autocompletion

about 4 years ago · Juan Pablo Isaza Relatório

0

As Snoweuph has already stated, their answer is incorrect — you are able to set minimum and maximum values using setMinValue() and setMaxValue().

Here's what that looks like in code:

data = new SlashCommandBuilder()
    .setName("example")
    .setDescription("wow look at me!")
    .addIntegerOption(option =>
        option.setName("integer")
            .setDescription("some name i guess")
            .setMinValue(0)
            .setMaxValue(22)
    );

And in Discord, the user will receive an error message if the integer they chose is too large or too small.

Example Discord chat log here:

enter image description here

This also works with Number options (docs).

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