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')
}),
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:
This also works with Number options (docs).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With