New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(Activity): accept non-string application ids #1513
base: master
Are you sure you want to change the base?
Conversation
Related to:
It seems as though a numeric response for snowflake types is intended. A better fix may be to have a |
structs.go
Outdated
@@ -2174,7 +2174,7 @@ func (activity *Activity) UnmarshalJSON(b []byte) error { | |||
Type ActivityType `json:"type"` | |||
URL string `json:"url,omitempty"` | |||
CreatedAt int64 `json:"created_at"` | |||
ApplicationID string `json:"application_id,omitempty"` | |||
ApplicationID interface{} `json:"application_id,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's only an integer number, I think it'd be better to use json.Number
for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good shout - I've just made that change
wsapi.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we should fix this at some point, these changes are unrelated, please remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair. My IDE is auto formatting here
I've been writing some code to read VoiceStates on application start-up and noticed it wasn't finding records where I would expect.
I noticed this coincided with the error
wsapi.go:646:onEvent() error unmarshalling GUILD_CREATE event, json: cannot unmarshal number into Go struct field Presence.presences.activities of type string
.After doing some digging, I realised that discord is sending along activities with an
application_id
of1
in some cases (Note that is1
the integer, not"1"
the string)This causes the
GUILD_CREATE
event (and others) to fail parsing and not get added to the state, meaning I then have no way of accessing the current voice states when my app starts up.I have run my app against my
discordgo
fork and it is now working as expected.I know this logic isn't ideal, but I don't know of a better way to fix it given:
Example activity with a bad app id:
Out of 1142 activities found on this
GUILD_CREATE
event, the above is the single activity with a non-string application_id.