diff --git a/aiogram/dispatcher/ctx.py b/aiogram/dispatcher/ctx.py index f1ecce68..18229125 100644 --- a/aiogram/dispatcher/ctx.py +++ b/aiogram/dispatcher/ctx.py @@ -7,7 +7,10 @@ from ..utils import context def _get(key, default=None, no_error=False): result = context.get_value(key, default) if not no_error and result is None: - raise RuntimeError(f"Context is not configured for '{key}'") + raise RuntimeError(f"Key '{key}' does not exist in the current execution context!\n" + f"Maybe asyncio task factory is not configured!\n" + f"\t>>> from aiogram.utils import context\n" + f"\t>>> loop.set_task_factory(context.task_factory)") return result diff --git a/aiogram/types/base.py b/aiogram/types/base.py index 7a4bdd56..e291afe5 100644 --- a/aiogram/types/base.py +++ b/aiogram/types/base.py @@ -138,10 +138,8 @@ class TelegramObject(metaclass=MetaTelegramObject): @property def bot(self): - bot = get_value('bot') - if bot is None: - raise RuntimeError('Can not found bot instance in current context!') - return bot + from ..dispatcher import ctx + return ctx.get_bot() def to_python(self) -> typing.Dict: """