forked from pothtonswer/discordmuffin
feat: min and max constraints for slash command options (#1026)
* feat: min and max constraints for slash command options * fix: typo * feat: changed slash command options min-max values to float * feat: improved min max constraints * feat: removed helper functions * fix(examples): helper functions * feat(components): made MaxValues int in SelectMenu * fix(examples/components): MaxValues * feat(interactions#ApplicationCommandOption): removed pointer from MaxValue * feat(examples): removed helper functions for MinValue and MinValues * fix(examples): removed newOptionalInt
This commit is contained in:
parent
58b2c2e55d
commit
a4d694738f
4 changed files with 12 additions and 2 deletions
|
@ -175,7 +175,7 @@ type SelectMenu struct {
|
||||||
// The text which will be shown in the menu if there's no default options or all options was deselected and component was closed.
|
// The text which will be shown in the menu if there's no default options or all options was deselected and component was closed.
|
||||||
Placeholder string `json:"placeholder"`
|
Placeholder string `json:"placeholder"`
|
||||||
// This value determines the minimal amount of selected items in the menu.
|
// This value determines the minimal amount of selected items in the menu.
|
||||||
MinValues int `json:"min_values,omitempty"`
|
MinValues *int `json:"min_values,omitempty"`
|
||||||
// This value determines the maximal amount of selected items in the menu.
|
// This value determines the maximal amount of selected items in the menu.
|
||||||
// If MaxValues or MinValues are greater than one then the user can select multiple items in the component.
|
// If MaxValues or MinValues are greater than one then the user can select multiple items in the component.
|
||||||
MaxValues int `json:"max_values,omitempty"`
|
MaxValues int `json:"max_values,omitempty"`
|
||||||
|
|
|
@ -314,6 +314,7 @@ var (
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
case "multi":
|
case "multi":
|
||||||
|
minValues := 1
|
||||||
response = &discordgo.InteractionResponse{
|
response = &discordgo.InteractionResponse{
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
Data: &discordgo.InteractionResponseData{
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
@ -328,7 +329,7 @@ var (
|
||||||
Placeholder: "Select tags to search on StackOverflow",
|
Placeholder: "Select tags to search on StackOverflow",
|
||||||
// This is where confusion comes from. If you don't specify these things you will get single item select.
|
// This is where confusion comes from. If you don't specify these things you will get single item select.
|
||||||
// These fields control the minimum and maximum amount of selected items.
|
// These fields control the minimum and maximum amount of selected items.
|
||||||
MinValues: 1,
|
MinValues: &minValues,
|
||||||
MaxValues: 3,
|
MaxValues: 3,
|
||||||
Options: []discordgo.SelectMenuOption{
|
Options: []discordgo.SelectMenuOption{
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,6 +32,8 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
integerOptionMinValue = 1.0
|
||||||
|
|
||||||
commands = []*discordgo.ApplicationCommand{
|
commands = []*discordgo.ApplicationCommand{
|
||||||
{
|
{
|
||||||
Name: "basic-command",
|
Name: "basic-command",
|
||||||
|
@ -59,6 +61,8 @@ var (
|
||||||
Type: discordgo.ApplicationCommandOptionInteger,
|
Type: discordgo.ApplicationCommandOptionInteger,
|
||||||
Name: "integer-option",
|
Name: "integer-option",
|
||||||
Description: "Integer option",
|
Description: "Integer option",
|
||||||
|
MinValue: &integerOptionMinValue,
|
||||||
|
MaxValue: 10,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -94,6 +94,7 @@ type ApplicationCommandOption struct {
|
||||||
// NOTE: This feature was on the API, but at some point developers decided to remove it.
|
// NOTE: This feature was on the API, but at some point developers decided to remove it.
|
||||||
// So I commented it, until it will be officially on the docs.
|
// So I commented it, until it will be officially on the docs.
|
||||||
// Default bool `json:"default"`
|
// Default bool `json:"default"`
|
||||||
|
|
||||||
ChannelTypes []ChannelType `json:"channel_types"`
|
ChannelTypes []ChannelType `json:"channel_types"`
|
||||||
Required bool `json:"required"`
|
Required bool `json:"required"`
|
||||||
Options []*ApplicationCommandOption `json:"options"`
|
Options []*ApplicationCommandOption `json:"options"`
|
||||||
|
@ -101,6 +102,10 @@ type ApplicationCommandOption struct {
|
||||||
// NOTE: mutually exclusive with Choices.
|
// NOTE: mutually exclusive with Choices.
|
||||||
Autocomplete bool `json:"autocomplete"`
|
Autocomplete bool `json:"autocomplete"`
|
||||||
Choices []*ApplicationCommandOptionChoice `json:"choices"`
|
Choices []*ApplicationCommandOptionChoice `json:"choices"`
|
||||||
|
// Minimal value of number/integer option.
|
||||||
|
MinValue *float64 `json:"min_value,omitempty"`
|
||||||
|
// Maximum value of number/integer option.
|
||||||
|
MaxValue float64 `json:"max_value,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplicationCommandOptionChoice represents a slash command option choice.
|
// ApplicationCommandOptionChoice represents a slash command option choice.
|
||||||
|
|
Loading…
Reference in a new issue