MCPcopy Index your code
hub / github.com/nonebot/nonebot2 / get_app

Function get_app

nonebot/__init__.py:154–172  ·  view source on GitHub ↗

获取全局 {ref}`nonebot.drivers.ASGIMixin` 对应的 Server App 对象。 返回: Server App 对象 异常: AssertionError: 全局 Driver 对象不是 {ref}`nonebot.drivers.ASGIMixin` 类型 ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化 ({ref}`nonebot.init ` 尚未调用) 用法:

()

Source from the content-addressed store, hash-verified

152
153
154def get_app() -> Any:
155 """获取全局 {ref}`nonebot.drivers.ASGIMixin` 对应的 Server App 对象。
156
157 返回:
158 Server App 对象
159
160 异常:
161 AssertionError: 全局 Driver 对象不是 {ref}`nonebot.drivers.ASGIMixin` 类型
162 ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化
163 ({ref}`nonebot.init <nonebot.init>` 尚未调用)
164
165 用法:
166 ```python
167 app = nonebot.get_app()
168 ```
169 """
170 driver = get_driver()
171 assert isinstance(driver, ASGIMixin), "app object is only available for asgi driver"
172 return driver.server_app
173
174
175def get_asgi() -> Any:

Callers 1

test_get_appFunction · 0.90

Calls 1

get_driverFunction · 0.85

Tested by 1

test_get_appFunction · 0.72