kordlib / kord

Idiomatic Kotlin Wrapper for The Discord API
MIT License
929 stars 81 forks source link

Kord fails to deserialize a `GuildCreate` event with a unavailable guild #627

Open MrPowerGamerBR opened 2 years ago

MrPowerGamerBR commented 2 years ago
Caused by: kotlinx.serialization.MissingFieldException: Fields [name, icon, owner_id, region, afk_channel_id, afk_timeout, verification_level, default_message_notifications, explicit_content_filter, roles, emojis, features, mfa_level, application_id, system_channel_id, system_channel_flags, rules_channel_id, vanity_url_code, description, banner, premium_tier, preferred_locale, public_updates_channel_id, nsfw_level, premium_progress_bar_enabled] are required for type with serial name 'dev.kord.common.entity.DiscordGuild', but they were missing at path: $.d
        at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:40)
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43)
        at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70)
        at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableElement(StreamingJsonDecoder.kt:111)
        at kotlinx.serialization.encoding.CompositeDecoder$DefaultImpls.decodeSerializableElement$default(Decoding.kt:537)
        at dev.kord.gateway.Event$DeserializationStrategy.getByDispatchEvent(Event.kt:167)
        at dev.kord.gateway.Event$DeserializationStrategy.deserialize(Event.kt:80)
        at dev.kord.gateway.Event$DeserializationStrategy.deserialize(Event.kt:48)
        at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:59)
        at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:38)
        ... 9 common frames omitted

Event Payload:

{"d": {"id": "989200553198375033", "unavailable": true}, "s": 27007, "t": "GUILD_CREATE", "op": 0}
HopeBaron commented 2 years ago

Seems like a partial guild object -- will look into it

HopeBaron commented 2 years ago

A fix should be deployed on branch #627 -- will keep you up to date

lukellmann commented 2 years ago

This might also be relevant for discord's docs. This doesn't suggest that you can receive a guild with only those two fields. Maybe you could create an issue there too.

MrPowerGamerBR commented 2 years ago

@Lukellmann while it isn't documented in the Guild Create section for some reason, they do provide an example of the object here: https://discord.com/developers/docs/resources/guild#unavailable-guild-object-example-unavailable-guild

There is also a PR about it here: https://github.com/discord/discord-api-docs/pull/5122

lukellmann commented 2 years ago

Yeah, I'm aware of the unavailable guild object (it is already modeled in kord and used in the ready event). But good to see that there is already an issue and PR about this 👍