消息元素
消息元素实现
所有的 Message.Element 特殊实现类型均定义在包 love.forte.simbot.component.qguild.message 中。
它们都继承了 love.forte.simbot.component.qguild.message.QGMessageElement。
- QGArk
对 API 模块中 Ark 消息的包装体,可用来发送
Ark消息。- QGContentText
- QGMarkdown
- QGAttachmentMessage
- QGEmbed
对 API 模块中 Embed 消息的包装体,可用来发送
Embed消息。- QGReference
发送消息时,QQ频道的消息引用。与官方发送消息API中的
reference对应。- QGReplyTo
发送消息时,指定一个需要回复的目标消息ID。
- QGMedia
- QGKeyboards
对 API 模块中
MessageKeyboards的包装体,可用来发送包含多行、多按钮的 Markdown 消息按钮。 旧的QGKeyboard只包装单个MessageKeyboard,自4.4.0起应改用QGKeyboards。- QGKeyboard
旧的单按钮包装体,只能包装单个
MessageKeyboard,无法完整表达官方keyboard.content.rows[].buttons[]结构。 请使用QGKeyboards替代。
发送消息
在simbot中,使用组件的消息元素与使用其他消息元素别无二致, 通常使用 SendSupport 和 ReplySupport 的实现类中提供的 send(...) 和 reply(..) API 发送消息。
前者多由 行为对象 中的一些类型实现(例如QGMember、 QGTextChannel), 而后者则通常由与消息相关的事件实现(例如 QGAtMessageCreateEvent)。
此处以 QGTextChannel 为例, send 可以使用拼接后的消息链、字符串或单独的消息元素作为参数。
Markdown 消息按钮
自 4.4.0 起,群聊和单聊 Markdown 消息按钮使用 QGKeyboards/MessageKeyboards 表示。 它支持按行组织多个按钮,并在发送体中仍序列化为官方 API 的 keyboard 字段。