@@ -1212,16 +1212,61 @@ const (
1212
1212
1213
1213
// Interaction is the base "thing" that is sent when a user invokes a command, and is the same for Slash Commands and other future interaction types.
1214
1214
type Interaction struct {
1215
- ID int64 `json:"id,string"` // id of the interaction
1216
- ApplicationID int64 `json:"application_id,string"` // id of the application this interaction is for
1217
- Kind InteractionType `json:"type"` // the type of interaction
1218
- Data * ApplicationCommandInteractionData `json:"data"` // the command data payload
1219
- GuildID int64 `json:"guild_id,string"` // the guild it was sent from
1220
- ChannelID int64 `json:"channel_id,string"` // the channel it was sent from
1221
- Member * Member `json:"member"` // member object guild member data for the invoking user, including permissions
1222
- User * User `json:"user"` // object user object for the invoking user, if invoked in a DM
1223
- Token string `json:"token"` // a continuation token for responding to the interaction
1224
- Version int `json:"version"` // read-only property, always
1215
+ ID int64 `json:"id,string"` // id of the interaction
1216
+ ApplicationID int64 `json:"application_id,string"` // id of the application this interaction is for
1217
+ Kind InteractionType `json:"type"` // the type of interaction
1218
+ GuildID int64 `json:"guild_id,string"` // the guild it was sent from
1219
+ ChannelID int64 `json:"channel_id,string"` // the channel it was sent from
1220
+ Member * Member `json:"member"` // member object guild member data for the invoking user, including permissions
1221
+ User * User `json:"user"` // object user object for the invoking user, if invoked in a DM
1222
+ Token string `json:"token"` // a continuation token for responding to the interaction
1223
+ Version int `json:"version"` // read-only property, always
1224
+
1225
+ DataCommand * ApplicationCommandInteractionData
1226
+ }
1227
+
1228
+ type interactionTemp struct {
1229
+ ID int64 `json:"id,string"` // id of the interaction
1230
+ ApplicationID int64 `json:"application_id,string"` // id of the application this interaction is for
1231
+ Kind InteractionType `json:"type"` // the type of interaction
1232
+ Data json.RawMessage `json:"data"` // data payload
1233
+ GuildID int64 `json:"guild_id,string"` // the guild it was sent from
1234
+ ChannelID int64 `json:"channel_id,string"` // the channel it was sent from
1235
+ Member * Member `json:"member"` // member object guild member data for the invoking user, including permissions
1236
+ User * User `json:"user"` // object user object for the invoking user, if invoked in a DM
1237
+ Token string `json:"token"` // a continuation token for responding to the interaction
1238
+ Version int `json:"version"` // read-only property, always
1239
+ }
1240
+
1241
+ // Interaction requires custom unmarshal logic because of the Data field being dependant on the interaction type
1242
+ func (a * Interaction ) UnmarshalJSON (b []byte ) error {
1243
+ var temp * interactionTemp
1244
+ err := json .Unmarshal (b , & temp )
1245
+ if err != nil {
1246
+ return err
1247
+ }
1248
+
1249
+ * a = Interaction {
1250
+ ID : temp .ID ,
1251
+ ApplicationID : temp .ApplicationID ,
1252
+ Kind : temp .Kind ,
1253
+ GuildID : temp .GuildID ,
1254
+ ChannelID : temp .ChannelID ,
1255
+ Member : temp .Member ,
1256
+ User : temp .User ,
1257
+ Token : temp .Token ,
1258
+ Version : temp .Version ,
1259
+ }
1260
+
1261
+ switch temp .Kind {
1262
+ case InteractionTypeApplicationCommand :
1263
+ err = json .Unmarshal (temp .Data , & a .DataCommand )
1264
+ if err != nil {
1265
+ return err
1266
+ }
1267
+ }
1268
+
1269
+ return nil
1225
1270
}
1226
1271
1227
1272
type InteractionType int
0 commit comments