Raise Exception if there's no bot instance in context

This commit is contained in:
Oleg A 2019-02-25 13:23:50 +03:00
parent dd899c9ca0
commit 4e4bbdfc7e
3 changed files with 93 additions and 1 deletions

View file

@ -142,7 +142,13 @@ class TelegramObject(ContextInstanceMixin, metaclass=MetaTelegramObject):
@property
def bot(self):
from ..bot.bot import Bot
return Bot.get_current()
bot = Bot.get_current()
if bot is None:
raise RuntimeError("Can't get bot instance from context. "
"You can fix it with setting current instance: "
"'Bot.set_current(bot_instance)'")
return bot
def to_python(self) -> typing.Dict:
"""