From e6da0d0fae05b3447c9c648550367d1b6d2288f3 Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 22 Dec 2023 16:37:38 -0600 Subject: [PATCH] Add unhanlded focus option for register command, improve both, comments --- commands.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/commands.go b/commands.go index 00b4294..86b4a6a 100644 --- a/commands.go +++ b/commands.go @@ -96,14 +96,17 @@ func CodeCommandHandler(session *discordgo.Session, interaction *discordgo.Inter } } default: + // An option was focused, but it does not have a handler. + var focusedOption *discordgo.ApplicationCommandInteractionDataOption focusedIndex := 0 for i, option := range data.Options { if option.Focused { + focusedOption = option focusedIndex = i break } } - log.WithFields(logrus.Fields{"focusedIndex": focusedIndex}).Warn("Unhandled autocomplete option") + log.WithFields(logrus.Fields{"focusedIndex": focusedIndex, "focusedOption": focusedOption.Name, "focusedOption.value": focusedOption.Value}).Warn("Unhandled autocomplete option") return } @@ -278,6 +281,7 @@ func RegisterCommandHandler(session *discordgo.Session, interaction *discordgo.I // }, // }) + // Autocomplete is used to provide the user with a list of locations to choose from case discordgo.InteractionApplicationCommandAutocomplete: data := interaction.ApplicationCommandData() var choices []*discordgo.ApplicationCommandOptionChoice @@ -299,6 +303,20 @@ func RegisterCommandHandler(session *discordgo.Session, interaction *discordgo.I Value: strconv.Itoa(int(location.id)), } } + + default: + // An option was focused, but it does not have a handler. + var focusedOption *discordgo.ApplicationCommandInteractionDataOption + focusedIndex := 0 + for i, option := range data.Options { + if option.Focused { + focusedOption = option + focusedIndex = i + break + } + } + + log.WithFields(logrus.Fields{"focusedIndex": focusedIndex, "focusedOption": focusedOption.Name, "focusedOption.value": focusedOption.Value}).Warn("Unhandled autocomplete option") } err := session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{