kordlib/kord

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

MrPowerGamerBR opened this issue ยท 5 comments

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}

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

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

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.

@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: discord/discord-api-docs#5122

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 ๐Ÿ‘