Skip to content

Commit

Permalink
feat(interactions): add GetOption method to interaction data structs (#…
Browse files Browse the repository at this point in the history
…1535)

* Add ApplicationCommandInteractionData.GetOption
* Add ApplicationCommandInteractionDataOption.GetOption

---------

Co-authored-by: Fedor Lapshin <[email protected]>
  • Loading branch information
NotYusta and FedorLap2006 authored Oct 6, 2024
1 parent 7fded9f commit 02e7ea5
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions interactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,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.
Expand Down Expand Up @@ -428,6 +440,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 {
Expand Down

0 comments on commit 02e7ea5

Please sign in to comment.