aboutsummaryrefslogtreecommitdiff
path: root/discord/shard.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2020-09-14 03:49:21 -0400
committerRapptz <[email protected]>2020-09-23 03:21:20 -0400
commitbf8ca5899689863487a4ec1c343ead9a874cbde9 (patch)
treed4f2b44a33e7280c12cfa3999e7eca7285db9813 /discord/shard.py
parentPass default intents if not explicitly given (diff)
downloaddiscord.py-bf8ca5899689863487a4ec1c343ead9a874cbde9.tar.xz
discord.py-bf8ca5899689863487a4ec1c343ead9a874cbde9.zip
Add a special exception for required privileged intents
Diffstat (limited to 'discord/shard.py')
-rw-r--r--discord/shard.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/discord/shard.py b/discord/shard.py
index 00a7a117..3587c097 100644
--- a/discord/shard.py
+++ b/discord/shard.py
@@ -34,7 +34,15 @@ from .state import AutoShardedConnectionState
from .client import Client
from .backoff import ExponentialBackoff
from .gateway import *
-from .errors import ClientException, InvalidArgument, HTTPException, GatewayNotFound, ConnectionClosed
+from .errors import (
+ ClientException,
+ InvalidArgument,
+ HTTPException,
+ GatewayNotFound,
+ ConnectionClosed,
+ PrivilegedIntentsRequired,
+)
+
from . import utils
from .enums import Status
@@ -125,6 +133,9 @@ class Shard:
return
if isinstance(e, ConnectionClosed):
+ if e.code == 4014:
+ self._queue_put(EventItem(EventType.terminate, self, PrivilegedIntentsRequired(self.id)))
+ return
if e.code != 1000:
self._queue_put(EventItem(EventType.close, self, e))
return
@@ -408,8 +419,11 @@ class AutoShardedClient(Client):
item = await self.__queue.get()
if item.type == EventType.close:
await self.close()
- if isinstance(item.error, ConnectionClosed) and item.error.code != 1000:
- raise item.error
+ if isinstance(item.error, ConnectionClosed):
+ if item.error.code != 1000:
+ raise item.error
+ if item.error.code == 4014:
+ raise PrivilegedIntentsRequired(item.shard.id) from None
return
elif item.type in (EventType.identify, EventType.resume):
await item.shard.reidentify(item.error)