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

Function get_asgi

nonebot/__init__.py:175–196  ·  view source on GitHub ↗

获取全局 {ref}`nonebot.drivers.ASGIMixin` 对应的 [ASGI](https://asgi.readthedocs.io/) 对象。 返回: ASGI 对象 异常: AssertionError: 全局 Driver 对象不是 {ref}`nonebot.drivers.ASGIMixin` 类型 ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化 ({ref}`nonebot.init <nonebot.in

()

Source from the content-addressed store, hash-verified

173
174
175def get_asgi() -> Any:
176 """获取全局 {ref}`nonebot.drivers.ASGIMixin` 对应的
177 [ASGI](https://asgi.readthedocs.io/) 对象。
178
179 返回:
180 ASGI 对象
181
182 异常:
183 AssertionError: 全局 Driver 对象不是 {ref}`nonebot.drivers.ASGIMixin` 类型
184 ValueError: 全局 {ref}`nonebot.drivers.Driver` 对象尚未初始化
185 ({ref}`nonebot.init <nonebot.init>` 尚未调用)
186
187 用法:
188 ```python
189 asgi = nonebot.get_asgi()
190 ```
191 """
192 driver = get_driver()
193 assert isinstance(driver, ASGIMixin), (
194 "asgi object is only available for asgi driver"
195 )
196 return driver.asgi
197
198
199def get_bot(self_id: str | None = None) -> Bot:

Callers 1

test_get_asgiFunction · 0.90

Calls 1

get_driverFunction · 0.85

Tested by 1

test_get_asgiFunction · 0.72