I want to write a slash mand 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 mand 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 mand 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')
}),
I want to write a slash mand 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 mand 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 mand 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')
}),
Share
Improve this question
edited Oct 13, 2021 at 20:04
MrMythical
9,0413 gold badges21 silver badges48 bronze badges
asked Oct 13, 2021 at 19:47
SnoweuphSnoweuph
911 silver badge8 bronze badges
2
- 2 I don't think you can set the range, I believe you have to handle that in your callback (check if it's bigger than max or smaller than min) – MrMythical Commented Oct 13, 2021 at 20:08
- 2 thx for fixing my writing :) – Snoweuph Commented Oct 13, 2021 at 20:13
2 Answers
Reset to default 5As 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).
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"})
ephemeral lets only the user of the mand 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 autopletion