Add a special exception for required privileged intents

This commit is contained in:
Rapptz
2020-09-14 03:49:21 -04:00
parent 4d813da9e1
commit bf8ca58996
4 changed files with 46 additions and 3 deletions

View File

@ -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)