1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-12-01 08:37:23 +00:00

examples: Update Autocomplete example

This commit is contained in:
twoscott 2022-05-31 13:33:02 +01:00 committed by diamondburned
parent 33fbc1a1a2
commit ea5251df0f

View file

@ -42,7 +42,7 @@ func main() {
}, },
} }
case *discord.AutocompleteInteraction: case *discord.AutocompleteInteraction:
allChoices := []api.AutocompleteChoice{ allChoices := api.AutocompleteStringChoices{
{Name: "Choice A", Value: "Choice A"}, {Name: "Choice A", Value: "Choice A"},
{Name: "Choice B", Value: "Choice B"}, {Name: "Choice B", Value: "Choice B"},
{Name: "Choice C", Value: "Choice C"}, {Name: "Choice C", Value: "Choice C"},
@ -51,8 +51,8 @@ func main() {
{Name: "Mno Pqr", Value: "Mnopqr"}, {Name: "Mno Pqr", Value: "Mnopqr"},
{Name: "Stu Vwx", Value: "Stuvwx"}, {Name: "Stu Vwx", Value: "Stuvwx"},
} }
query := strings.ToLower(d.Options[0].Value) query := strings.ToLower(d.Options[0].String())
var choices []api.AutocompleteChoice var choices api.AutocompleteStringChoices
for _, choice := range allChoices { for _, choice := range allChoices {
if strings.HasPrefix(strings.ToLower(choice.Name), query) || if strings.HasPrefix(strings.ToLower(choice.Name), query) ||
strings.HasPrefix(strings.ToLower(choice.Value), query) { strings.HasPrefix(strings.ToLower(choice.Value), query) {