@@ -442,7 +442,7 @@ proc reconnect(s: Shard) {.async.} =
442442 s.reconnecting = true
443443 s.retry_info.attempts += 1
444444
445- var url = s.resumeGatewayUrl
445+ var url = if s.resumeGatewayUrl == " " : s.gatewayUrl else : s.resumeGatewayUrl
446446 var query = " ?v=" & $ s.client.gatewayVersion
447447 when defined (discordEtf): query &= " &encoding=etf"
448448 if not url.endsWith (" /" ): url &= " /"
@@ -577,17 +577,7 @@ proc handleSocketMessage(s: Shard) {.async.} =
577577 var data: JsonNode
578578
579579 when defined (discordCompress):
580- if packet[0 ] == Binary :
581- packet[1 ] = uncompress (packet[1 ])
582- # buffer &= packet[1]
583- # if len(packet[1]) >= 4:
584- # if packet[1][^4..^1] == zlib_suffix:
585- # packet[1] = uncompress(buffer)
586- # buffer = ""
587- # else:
588- # return
589- # else:
590- # return
580+ if packet[0 ] == Binary : packet[1 ] = uncompress (packet[1 ])
591581
592582 try :
593583 when defined (discordEtf):
@@ -598,7 +588,7 @@ proc handleSocketMessage(s: Shard) {.async.} =
598588 s.logShard (" A zombied connection was detected." )
599589 else :
600590 s.logShard (
601- " An error occurred while parsing data: " & packet[1 ]
591+ fmt " Received non-JSON message from gateway: ' { packet[1 ]} ' "
602592 )
603593 autoreconnect = s.handleDisconnect (packet[1 ])
604594
@@ -657,12 +647,10 @@ proc handleSocketMessage(s: Shard) {.async.} =
657647 await s.identify ()
658648 else :
659649 discard
660- if not reconnectable:
661- raise newException (Exception , " Fatal error occurred." )
662650
663- if packet[0 ] == Close :
664- if not autoreconnect:
665- autoreconnect = s.handleDisconnect (packet[1 ])
651+ # if packet[0] == Close:
652+ # if not autoreconnect:
653+ # autoreconnect = s.handleDisconnect(packet[1])
666654
667655 s.stop = true
668656 s.reset ()
@@ -674,9 +662,11 @@ proc handleSocketMessage(s: Shard) {.async.} =
674662 if not s.networkError: await s.handleSocketMessage ()
675663 else :
676664 let info = extractCloseData (packet[1 ])
665+ var reason = info.reason
666+ if info.code == 4014 : reason &= " Check if your priviliged intents you listed are enabled on the OAuth2 Bot Applications section via https://discord.dev/"
677667 raise newException (
678668 Exception ,
679- " Fatal discord gateway error: " & " [ " & ($ info.code)& " ] " & info. reason
669+ " Fatal discord gateway error: " & " [ " & ($ info.code)& " ] " & reason
680670 )
681671
682672proc endSession * (discord: DiscordClient ) {.async .} =
@@ -721,11 +711,9 @@ proc startSession(s: Shard, url, query: string) {.async.} =
721711# It will try to forcefully put message content intent if not specified.
722712proc startSession * (discord: DiscordClient ,
723713 autoreconnect = true ;
724- gateway_intents: set [GatewayIntent ] = {
725- giGuilds, giGuildMessages,
726- giDirectMessages, giGuildVoiceStates,
727- giMessageContent
728- }; large_message_threshold, large_threshold = 50 ;
714+ gateway_intents: set [GatewayIntent ];
715+ content_intent = true ;
716+ large_message_threshold, large_threshold = 50 ;
729717 max_message_size = 5_000_000 ;
730718 gateway_version = 10 ;
731719 max_shards = none int ; shard_id = 0 ;
@@ -734,8 +722,7 @@ proc startSession*(discord: DiscordClient,
734722 # # Connects the client to Discord via gateway.
735723 # #
736724 # # - `gateway_intents` Allows you to subscribe to pre-defined events.
737- # # **NOTE:** When not specified this will default to:
738- # # `giGuilds, giGuildMessages, giDirectMessages, giGuildVoiceStates, giMessageContent`
725+ # # - `content_intent` Whether to use discord's priviliged message content on by default. (defaults to `true`)
739726 # #
740727 # # - `large_threshold` The number that would be considered a large guild (50-250).
741728 # # - `guild_subscriptions` **DEPRECATED** Whether or not to receive presence_update, typing_start events.
@@ -750,13 +737,13 @@ proc startSession*(discord: DiscordClient,
750737
751738 discord.autoreconnect = autoreconnect
752739
753- # assert gateway_intents.len == 0, "Gateway intents cannot be empty."
754740 discord.intents = gateway_intents
755741
756742 if giMessageContent notin discord.intents:
757- log ( " Warning: giMessageContent not specified this might cause issues. " )
743+ if content_intent: raise newException ( Exception , " giMessageContent not in intents, if you wish to turn it off set content_intent = false in startSession " )
758744
759745 discord.largeThreshold = large_threshold
746+
760747 if guild_subscriptions:
761748 log (" Warning: guild_subscriptions is deprecated." )
762749 discord.intents = discord.intents + {
@@ -768,8 +755,6 @@ proc startSession*(discord: DiscordClient,
768755
769756 discord.max_shards = max_shards.get (- 1 )
770757 discord.gatewayVersion = gateway_version
771- # when defined(discordv8):
772- # discord.gatewayVersion = 8
773758 when defined (discordv9):
774759 discord.gatewayVersion = 9
775760
@@ -782,9 +767,6 @@ proc startSession*(discord: DiscordClient,
782767 when defined (discordEtf):
783768 query &= " &encoding=etf"
784769
785- # when defined(discordCompress):
786- # query &= "&compress=zlib-stream"
787-
788770 if discord.shards.len == 0 :
789771 log (" Starting gateway session." )
790772
0 commit comments