nonebot 2 发送图片及其它特殊形式消息

您所在的位置:网站首页 很像女生的网名 nonebot 2 发送图片及其它特殊形式消息

nonebot 2 发送图片及其它特殊形式消息

2023-10-23 13:48| 来源: 网络整理| 查看: 265

在实现语录模块的时候碰到了发送本地图片的需求,询问群友之后得知可以使用MessageSegment类发送本地图片。

class MessageSegment(d: Union[Dict[str, Any], NoneType] = None, *, type_: Union[str, NoneType] = None, data: Union[Dict[str, str], NoneType] = None)

消息段,即表示成字典的 CQ 码。

除非遇到必须手动构造消息的情况,建议使用此类的静态方法构造,例如:

at_seg = MessageSegment.at(10001000)

可进行判等和加法操作,例如:

assert at_seg == MessageSegment.at(10001000) msg: Message = at_seg + MessageSegment.face(14) d: 当有此参数且此参数中有 type 字段时,由此参数构造消息段type_: 当没有传入 d 参数或 d 参数无法识别时,此参数必填,对应消息段的 type 字段data: 对应消息段的 data 字段

当没有正确传入类型参数时,抛出 ValueError。

def image(file: str, destruct: Union[bool, NoneType] = None, type: Union[str, NoneType] = None, cache: Union[bool, NoneType] = None, proxy: Union[bool, NoneType] = None, timeout: Union[int, NoneType] = None) ‑> MessageSegment

 组织图片消息

模块直接 Send 由 MessageSegment 组织的图片消息即可。

MessageSegment 类同时也可以组织视频、语音、戳一戳、匿名、链接、群分享好友分享等消息,详细内容可以查看相关文档相关文档 ->相关文档->



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3