Skip to content

Commit 1474f71

Browse files
fix(channel): make channel type decoding failsafe
return a default case if none matches
1 parent 1ebdca9 commit 1474f71

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Sources/DiscordKitCore/Objects/Data/Channel.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ public enum ChannelType: Int, Codable {
2626
case stageVoice = 13
2727
case directory = 14 // Hubs
2828
case forum = 15 // (still in development) a channel that can only contain threads
29+
30+
case unknown = -1 // An unknown value
31+
32+
public init(from decoder: Decoder) throws {
33+
let container = try decoder.singleValueContainer()
34+
self = Self(rawValue: try container.decode(Int.self)) ?? Self.unknown
35+
}
2936
}
3037

3138
public struct Channel: Identifiable, Codable, GatewayData, Equatable {

0 commit comments

Comments
 (0)