Skip to content

Commit

Permalink
feat: min and max constraints for slash command options (#1026)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
FedorLap2006 committed Feb 26, 2022
1 parent 58b2c2e commit a4d6947
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components.go
Expand Up @@ -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.
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 @@ -94,13 +94,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

0 comments on commit a4d6947

Please sign in to comment.