async def send(bot: NoneBot, event: CQEvent, message: Message_T, *, ensure_private: bool = False, ignore_failure: bool = True, **kwargs) -> Any: """Send a message ignoring failure by default.""" try: if ensure_private: event = event.copy() event['message_type'] = 'private' return await bot.send(event, message, **kwargs) except CQHttpError: if not ignore_failure: raise return None
async def send(bot: NoneBot, event: CQEvent, message: Message_T, *, ensure_private: bool = False, ignore_failure: bool = True, **kwargs) -> Any: """ 发送消息到指定事件的上下文中。 参数: bot: NoneBot 对象 event: 事件对象 message (nonebot.typing.Message_T): 要发送的消息内容 ensure_private: 确保消息发送到私聊,对于群组和讨论组消息上下文,会私聊发送者 ignore_failure: 发送失败时忽略 `CQHttpError` 异常 kwargs: 其它传入 `CQHttp.send()` 的命名参数 返回: Any {version}`1.1.0+`: 返回 CQHTTP 插件发送消息接口的调用返回值,具体见 aiocqhttp 的 [API 调用](https://aiocqhttp.nonebot.dev/#/what-happened#api-%E8%B0%83%E7%94%A8) 异常: CQHttpError: 发送失败时抛出,实际由 [aiocqhttp] 抛出,等价于 `aiocqhttp.Error` 用法: ```python await send(bot, event, 'hello') ``` """ try: if ensure_private: event = event.copy() event['message_type'] = 'private' return await bot.send(event, message, **kwargs) except CQHttpError: if not ignore_failure: raise return None