diff --git a/telethon/client/auth.py b/telethon/client/auth.py index b4a1c74a..9fcb1bce 100644 --- a/telethon/client/auth.py +++ b/telethon/client/auth.py @@ -483,6 +483,12 @@ class AuthMethods(MessageParseMethods, UserMethods): # region with blocks def __enter__(self): + if self._loop.is_running(): + raise RuntimeError( + 'You must use "async with" if the event loop ' + 'is running (i.e. you are inside an "async def")' + ) + return self.start() async def __aenter__(self): diff --git a/telethon/tl/custom/conversation.py b/telethon/tl/custom/conversation.py index 97b6816a..04f3ad5e 100644 --- a/telethon/tl/custom/conversation.py +++ b/telethon/tl/custom/conversation.py @@ -379,6 +379,12 @@ class Conversation(ChatGetter): fut.cancel() def __enter__(self): + if self._client.loop.is_running(): + raise RuntimeError( + 'You must use "async with" if the event loop ' + 'is running (i.e. you are inside an "async def")' + ) + return self._client.loop.run_until_complete(self.__aenter__()) async def __aenter__(self):