mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-19 15:36:02 +00:00
Fix AutoShardedClient to work with the new asyncio loop machinery
Fix #7675
This commit is contained in:
parent
049df7c586
commit
8d4f08a5e7
@ -235,9 +235,7 @@ class Client:
|
||||
return self.ws
|
||||
|
||||
def _get_state(self, **options: Any) -> ConnectionState:
|
||||
return ConnectionState(
|
||||
dispatch=self.dispatch, handlers=self._handlers, hooks=self._hooks, http=self.http, loop=self.loop, **options
|
||||
)
|
||||
return ConnectionState(dispatch=self.dispatch, handlers=self._handlers, hooks=self._hooks, http=self.http, **options)
|
||||
|
||||
def _handle_ready(self) -> None:
|
||||
self._ready.set()
|
||||
@ -474,6 +472,11 @@ class Client:
|
||||
|
||||
_log.info('logging in using static token')
|
||||
|
||||
loop = asyncio.get_running_loop()
|
||||
self.loop = loop
|
||||
self.http.loop = loop
|
||||
self._connection.loop = loop
|
||||
|
||||
data = await self.http.static_login(token.strip())
|
||||
self._connection.user = ClientUser(state=self._connection, data=data)
|
||||
|
||||
@ -611,9 +614,6 @@ class Client:
|
||||
TypeError
|
||||
An unexpected keyword argument was received.
|
||||
"""
|
||||
self.loop = asyncio.get_running_loop()
|
||||
self.http.loop = self.loop
|
||||
self._connection.loop = self.loop
|
||||
await self.login(token)
|
||||
await self.connect(reconnect=reconnect)
|
||||
|
||||
|
@ -546,6 +546,7 @@ class HTTPClient:
|
||||
# Necessary to get aiohttp to stop complaining about session creation
|
||||
if self.connector is MISSING:
|
||||
self.connector = aiohttp.TCPConnector(loop=self.loop, limit=0)
|
||||
|
||||
self.__session = aiohttp.ClientSession(
|
||||
connector=self.connector, ws_response_class=DiscordClientWebSocketResponse, loop=self.loop
|
||||
)
|
||||
|
@ -333,7 +333,6 @@ class AutoShardedClient(Client):
|
||||
self.__shards = {}
|
||||
self._connection._get_websocket = self._get_websocket
|
||||
self._connection._get_client = lambda: self
|
||||
self.__queue = asyncio.PriorityQueue()
|
||||
|
||||
def _get_websocket(self, guild_id: Optional[int] = None, *, shard_id: Optional[int] = None) -> DiscordWebSocket:
|
||||
if shard_id is None:
|
||||
@ -426,6 +425,7 @@ class AutoShardedClient(Client):
|
||||
self._connection.shards_launched.set()
|
||||
|
||||
async def connect(self, *, reconnect: bool = True) -> None:
|
||||
self.__queue = asyncio.PriorityQueue()
|
||||
self._reconnect = reconnect
|
||||
await self.launch_shards()
|
||||
|
||||
|
@ -169,10 +169,10 @@ class ConnectionState:
|
||||
handlers: Dict[str, Callable],
|
||||
hooks: Dict[str, Callable],
|
||||
http: HTTPClient,
|
||||
loop: asyncio.AbstractEventLoop,
|
||||
**options: Any,
|
||||
) -> None:
|
||||
self.loop: asyncio.AbstractEventLoop = loop
|
||||
# Set later, after Client.login
|
||||
self.loop: asyncio.AbstractEventLoop = utils.MISSING
|
||||
self.http: HTTPClient = http
|
||||
self.max_messages: Optional[int] = options.get('max_messages', 1000)
|
||||
if self.max_messages is not None and self.max_messages <= 0:
|
||||
|
Loading…
x
Reference in New Issue
Block a user