Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: min and max constraints for slash command options #1026

Merged
merged 12 commits into from Feb 26, 2022
2 changes: 1 addition & 1 deletion components.go
Expand Up @@ -166,7 +166,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.
Placeholder string `json:"placeholder"`
// 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.
// If MaxValues or MinValues are greater than one then the user can select multiple items in the component.
MaxValues int `json:"max_values,omitempty"`
Expand Down
3 changes: 2 additions & 1 deletion examples/components/main.go
Expand Up @@ -314,6 +314,7 @@ var (
},
}
case "multi":
minValues := 1
response = &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Expand All @@ -328,7 +329,7 @@ var (
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.
// These fields control the minimum and maximum amount of selected items.
MinValues: 1,
MinValues: &minValues,
MaxValues: 3,
Options: []discordgo.SelectMenuOption{
{
Expand Down
4 changes: 4 additions & 0 deletions examples/slash_commands/main.go
Expand Up @@ -32,6 +32,8 @@ func init() {
}

var (
integerOptionMinValue = 1.0

commands = []*discordgo.ApplicationCommand{
{
Name: "basic-command",
Expand Down Expand Up @@ -59,6 +61,8 @@ var (
Type: discordgo.ApplicationCommandOptionInteger,
Name: "integer-option",
Description: "Integer option",
MinValue: &integerOptionMinValue,
MaxValue: 10,
Required: true,
},
{
Expand Down
5 changes: 5 additions & 0 deletions interactions.go
Expand Up @@ -89,13 +89,18 @@ type ApplicationCommandOption struct {
// 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.
// Default bool `json:"default"`

ChannelTypes []ChannelType `json:"channel_types"`
Required bool `json:"required"`
Options []*ApplicationCommandOption `json:"options"`

// NOTE: mutually exclusive with Choices.
Autocomplete bool `json:"autocomplete"`
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.
Expand Down