Initialize resources used by this class. Currently calls :meth:`get_me` to cache :attr:`bot` and calls :meth:`telegram.request.BaseRequest.initialize` for the request objects used by this bot. .. seealso:: :meth:`shutdown` .. versionadded:: 20.0
(self)
| 841 | return Message.de_json(result, self) |
| 842 | |
| 843 | async def initialize(self) -> None: |
| 844 | """Initialize resources used by this class. Currently calls :meth:`get_me` to |
| 845 | cache :attr:`bot` and calls :meth:`telegram.request.BaseRequest.initialize` for |
| 846 | the request objects used by this bot. |
| 847 | |
| 848 | .. seealso:: :meth:`shutdown` |
| 849 | |
| 850 | .. versionadded:: 20.0 |
| 851 | """ |
| 852 | if self._requests_initialized and self._bot_initialized: |
| 853 | self._LOGGER.debug("This Bot is already initialized.") |
| 854 | return |
| 855 | |
| 856 | # Initialize request objects if not already done |
| 857 | if not self._requests_initialized: |
| 858 | await asyncio.gather(self._request[0].initialize(), self._request[1].initialize()) |
| 859 | self._requests_initialized = True |
| 860 | |
| 861 | # Initialize bot user |
| 862 | # Since the bot is to be initialized only once, we can also use it for |
| 863 | # verifying the token passed and raising an exception if it's invalid. |
| 864 | try: |
| 865 | await self.get_me() |
| 866 | self._bot_initialized = True |
| 867 | except InvalidToken as exc: |
| 868 | raise InvalidToken(f"The token `{self._token}` was rejected by the server.") from exc |
| 869 | |
| 870 | async def shutdown(self) -> None: |
| 871 | """Stop & clear resources used by this class. Currently just calls |
no test coverage detected