diff --git a/interactions.go b/interactions.go index c562463af..aa2e159ec 100644 --- a/interactions.go +++ b/interactions.go @@ -326,6 +326,18 @@ type ApplicationCommandInteractionData struct { TargetID string `json:"target_id"` } +// GetOption finds and returns an application command option by its name. +func (d ApplicationCommandInteractionData) GetOption(name string) (option *ApplicationCommandInteractionDataOption) { + for _, opt := range d.Options { + if opt.Name == name { + option = opt + break + } + } + + return +} + // ApplicationCommandInteractionDataResolved contains resolved data of command execution. // Partial Member objects are missing user, deaf and mute fields. // Partial Channel objects only have id, name, type and permissions fields. @@ -408,6 +420,18 @@ type ApplicationCommandInteractionDataOption struct { Focused bool `json:"focused,omitempty"` } +// GetOption finds and returns an application command option by its name. +func (o ApplicationCommandInteractionDataOption) GetOption(name string) (option *ApplicationCommandInteractionDataOption) { + for _, opt := range o.Options { + if opt.Name == name { + option = opt + break + } + } + + return +} + // IntValue is a utility function for casting option value to integer func (o ApplicationCommandInteractionDataOption) IntValue() int64 { if o.Type != ApplicationCommandOptionInteger {