From f758cfc5388c07eccfc05e98696fd518b9883faf Mon Sep 17 00:00:00 2001 From: git-bruh Date: Mon, 7 Dec 2020 19:28:05 +0530 Subject: [PATCH] Wait for discord client to be ready --- main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 96cc849..8528f8d 100644 --- a/main.py +++ b/main.py @@ -37,7 +37,7 @@ message_store = {} class MatrixClient(nio.AsyncClient): - async def create(self): + async def create(self, discord_client): password = config["password"] timeout = 30000 @@ -58,6 +58,8 @@ class MatrixClient(nio.AsyncClient): self.add_ephemeral_callback( callbacks.typing_callback, nio.EphemeralEvent) + await discord_client.wait_until_ready() + matrix_logger.info("Syncing forever.") await self.sync_forever(timeout=timeout) @@ -161,7 +163,7 @@ class DiscordClient(discord.Client): self.matrix_client = MatrixClient( config["homeserver"], config["username"]) - self.bg_task = self.loop.create_task(self.matrix_client.create()) + self.bg_task = self.loop.create_task(self.matrix_client.create(self)) async def on_ready(self): print(f"Logged in as {self.user}")