@@ -20,8 +20,9 @@ type ModalSubmitInteraction struct {
2020func (i * ModalSubmitInteraction ) UnmarshalJSON (data []byte ) error {
2121 var interaction struct {
2222 rawInteraction
23- Data ModalSubmitInteractionData `json:"data"`
24- Message * Message `json:"message,omitempty"`
23+ Data ModalSubmitInteractionData `json:"data"`
24+ Message * Message `json:"message,omitempty"`
25+ Resolved ResolvedData
2526 }
2627 if err := json .Unmarshal (data , & interaction ); err != nil {
2728 return err
@@ -96,6 +97,7 @@ func (ModalSubmitInteraction) interaction() {}
9697type ModalSubmitInteractionData struct {
9798 CustomID string `json:"custom_id"`
9899 Components []LayoutComponent `json:"components"`
100+ Resolved ResolvedData `json:"resolved"`
99101}
100102
101103func (d * ModalSubmitInteractionData ) UnmarshalJSON (data []byte ) error {
@@ -131,7 +133,7 @@ func (d ModalSubmitInteractionData) Component(customID string) (InteractiveCompo
131133 return nil , false
132134}
133135
134- func (d ModalSubmitInteractionData ) TextInputComponent (customID string ) (TextInputComponent , bool ) {
136+ func (d ModalSubmitInteractionData ) TextInput (customID string ) (TextInputComponent , bool ) {
135137 if component , ok := d .Component (customID ); ok {
136138 textInputComponent , ok := component .(TextInputComponent )
137139 return textInputComponent , ok
@@ -140,7 +142,7 @@ func (d ModalSubmitInteractionData) TextInputComponent(customID string) (TextInp
140142}
141143
142144func (d ModalSubmitInteractionData ) OptText (customID string ) (string , bool ) {
143- if textInputComponent , ok := d .TextInputComponent (customID ); ok {
145+ if textInputComponent , ok := d .TextInput (customID ); ok {
144146 return textInputComponent .Value , true
145147 }
146148 return "" , false
@@ -153,7 +155,7 @@ func (d ModalSubmitInteractionData) Text(customID string) string {
153155 return ""
154156}
155157
156- func (d ModalSubmitInteractionData ) StringSelectMenuComponent (customID string ) (StringSelectMenuComponent , bool ) {
158+ func (d ModalSubmitInteractionData ) StringSelectMenu (customID string ) (StringSelectMenuComponent , bool ) {
157159 if component , ok := d .Component (customID ); ok {
158160 selectMenuComponent , ok := component .(StringSelectMenuComponent )
159161 return selectMenuComponent , ok
@@ -162,7 +164,7 @@ func (d ModalSubmitInteractionData) StringSelectMenuComponent(customID string) (
162164}
163165
164166func (d ModalSubmitInteractionData ) OptStringValues (customID string ) ([]string , bool ) {
165- if selectMenuComponent , ok := d .StringSelectMenuComponent (customID ); ok {
167+ if selectMenuComponent , ok := d .StringSelectMenu (customID ); ok {
166168 return selectMenuComponent .Values , true
167169 }
168170 return nil , false
@@ -174,3 +176,157 @@ func (d ModalSubmitInteractionData) StringValues(customID string) []string {
174176 }
175177 return nil
176178}
179+
180+ func (d ModalSubmitInteractionData ) UserSelectMenu (customID string ) (UserSelectMenuComponent , bool ) {
181+ if component , ok := d .Component (customID ); ok {
182+ selectMenuComponent , ok := component .(UserSelectMenuComponent )
183+ return selectMenuComponent , ok
184+ }
185+ return UserSelectMenuComponent {}, false
186+ }
187+
188+ func (d ModalSubmitInteractionData ) OptUsers (customID string ) ([]User , bool ) {
189+ if selectMenuComponent , ok := d .UserSelectMenu (customID ); ok {
190+ users := make ([]User , 0 , len (selectMenuComponent .Values ))
191+ for _ , userID := range selectMenuComponent .Values {
192+ if user , ok := d .Resolved .Users [userID ]; ok {
193+ users = append (users , user )
194+ }
195+ }
196+ return users , true
197+ }
198+ return nil , false
199+ }
200+
201+ func (d ModalSubmitInteractionData ) Users (customID string ) []User {
202+ if users , ok := d .OptUsers (customID ); ok {
203+ return users
204+ }
205+ return nil
206+ }
207+
208+ func (d ModalSubmitInteractionData ) RoleSelectMenu (customID string ) (RoleSelectMenuComponent , bool ) {
209+ if component , ok := d .Component (customID ); ok {
210+ selectMenuComponent , ok := component .(RoleSelectMenuComponent )
211+ return selectMenuComponent , ok
212+ }
213+ return RoleSelectMenuComponent {}, false
214+ }
215+
216+ func (d ModalSubmitInteractionData ) OptRoles (customID string ) ([]Role , bool ) {
217+ if selectMenuComponent , ok := d .RoleSelectMenu (customID ); ok {
218+ roles := make ([]Role , 0 , len (selectMenuComponent .Values ))
219+ for _ , roleID := range selectMenuComponent .Values {
220+ if role , ok := d .Resolved .Roles [roleID ]; ok {
221+ roles = append (roles , role )
222+ }
223+ }
224+ return roles , true
225+ }
226+ return nil , false
227+ }
228+
229+ func (d ModalSubmitInteractionData ) Roles (customID string ) []Role {
230+ if roles , ok := d .OptRoles (customID ); ok {
231+ return roles
232+ }
233+ return nil
234+ }
235+
236+ // MentionableValue is an interface for all values a [MentionableSelectMenuComponent] can return.
237+ // [User]
238+ // [ResolvedMember]
239+ // [Role]
240+ // [ResolvedChannel]
241+ type MentionableValue interface {
242+ isMentionableValue ()
243+ }
244+
245+ func (d ModalSubmitInteractionData ) MentionableSelectMenu (customID string ) (MentionableSelectMenuComponent , bool ) {
246+ if component , ok := d .Component (customID ); ok {
247+ selectMenuComponent , ok := component .(MentionableSelectMenuComponent )
248+ return selectMenuComponent , ok
249+ }
250+ return MentionableSelectMenuComponent {}, false
251+ }
252+
253+ func (d ModalSubmitInteractionData ) OptMentionables (customID string ) ([]Mentionable , bool ) {
254+ if selectMenuComponent , ok := d .MentionableSelectMenu (customID ); ok {
255+ mentionables := make ([]Mentionable , 0 , len (selectMenuComponent .Values ))
256+ for _ , id := range selectMenuComponent .Values {
257+ if user , ok := d .Resolved .Users [id ]; ok {
258+ mentionables = append (mentionables , user )
259+ continue
260+ }
261+ if role , ok := d .Resolved .Roles [id ]; ok {
262+ mentionables = append (mentionables , role )
263+ continue
264+ }
265+ }
266+ return mentionables , true
267+ }
268+ return nil , false
269+ }
270+
271+ func (d ModalSubmitInteractionData ) Mentionables (customID string ) []Mentionable {
272+ if mentionables , ok := d .OptMentionables (customID ); ok {
273+ return mentionables
274+ }
275+ return nil
276+ }
277+
278+ func (d ModalSubmitInteractionData ) ChannelSelectMenu (customID string ) (ChannelSelectMenuComponent , bool ) {
279+ if component , ok := d .Component (customID ); ok {
280+ selectMenuComponent , ok := component .(ChannelSelectMenuComponent )
281+ return selectMenuComponent , ok
282+ }
283+ return ChannelSelectMenuComponent {}, false
284+ }
285+
286+ func (d ModalSubmitInteractionData ) OptChannels (customID string ) ([]ResolvedChannel , bool ) {
287+ if selectMenuComponent , ok := d .ChannelSelectMenu (customID ); ok {
288+ channels := make ([]ResolvedChannel , 0 , len (selectMenuComponent .Values ))
289+ for _ , channelID := range selectMenuComponent .Values {
290+ if channel , ok := d .Resolved .Channels [channelID ]; ok {
291+ channels = append (channels , channel )
292+ }
293+ }
294+ return channels , true
295+ }
296+ return nil , false
297+ }
298+
299+ func (d ModalSubmitInteractionData ) Channels (customID string ) []ResolvedChannel {
300+ if channels , ok := d .OptChannels (customID ); ok {
301+ return channels
302+ }
303+ return nil
304+ }
305+
306+ func (d ModalSubmitInteractionData ) FileUpload (customID string ) (FileUploadComponent , bool ) {
307+ if component , ok := d .Component (customID ); ok {
308+ fileUploadComponent , ok := component .(FileUploadComponent )
309+ return fileUploadComponent , ok
310+ }
311+ return FileUploadComponent {}, false
312+ }
313+
314+ func (d ModalSubmitInteractionData ) OptAttachments (customID string ) ([]Attachment , bool ) {
315+ if fileUploadComponent , ok := d .FileUpload (customID ); ok {
316+ attachments := make ([]Attachment , 0 , len (fileUploadComponent .Values ))
317+ for _ , attachmentID := range fileUploadComponent .Values {
318+ if attachment , ok := d .Resolved .Attachments [attachmentID ]; ok {
319+ attachments = append (attachments , attachment )
320+ }
321+ }
322+ return attachments , true
323+ }
324+ return nil , false
325+ }
326+
327+ func (d ModalSubmitInteractionData ) Attachments (customID string ) []Attachment {
328+ if attachments , ok := d .OptAttachments (customID ); ok {
329+ return attachments
330+ }
331+ return nil
332+ }
0 commit comments