Lachee / discord-rpc-csharp

C# custom implementation for Discord Rich Presence. Not deprecated and still available!
MIT License
561 stars 93 forks source link

[BUG] RPC fails to process ready event as `premium_type` is null. #214

Closed jacksonrakena closed 1 year ago

jacksonrakena commented 1 year ago

Describe the bug DiscordRPC fails to process a DISPATCH event because it fails to convert a null value for premium_type to the PremiumType enum.

To Reproduce I can only reproduce this behavior with specific users, but I believe that this issue only occurs on users without Nitro (where premium_type should be 0, but for some reason is null.

Expected behavior DiscordRPC successfully parses the event.

Desktop (please complete the following information):

Additional context I patched DiscordRPC to add a ? operand to the PremiumType Premium field in User.cs and that resolved this issue, although this would change the DiscordRPC API spec and could impact other users.

Logs

--------------------------------
14:11:32.911 | INF [Abyssal.RichPresence] Handling Response. Cmd: Dispatch, Event: Ready
--------------------------------
14:11:32.912 | INF [Abyssal.RichPresence] Connection established with the RPC
--------------------------------
14:11:32.920 | ERR [Abyssal.RichPresence] Failed to process event! Error converting value {null} to type 'DiscordRPC.User+PremiumType'. Path 'user.premium_type'.
--------------------------------
14:11:32.921 | ERR [Abyssal.RichPresence] Data: {"cmd":"DISPATCH","data":{"v":1,"config":{"cdn_host":"cdn.discordapp.com","api_endpoint":"//ptb.discord.com/api","environment":"production"},"user":{"id":"[[removed]]","username":"[[removed]]","discriminator":"3826","avatar":"[[removed]]","avatar_decoration":null,"bot":false,"flags":160,"premium_type":null}},"evt":"READY","nonce":null}
--------------------------------
Lachee commented 1 year ago

This has been resolved.