platforms.discord_rich_content module
Serialize Discord rich message content into LLM-visible text.
- platforms.discord_rich_content.serialize_embed(embed)[source]
Serialize a single Discord embed into XML-ish text for the LLM.
Renders an embed (author, title, url, description, fields, image, thumbnail, footer, video, timestamp, color, provider) into an indented
<embed>...</embed>block so the model can read structured embed content that would otherwise be invisible in the plain message body. Any embed keys not covered by a dedicated tag are dumped into a<raw_json>fallback rather than dropped, and an embed with no renderable content yields an empty string.It seeds a
rawdict via_dict_from_embedand then delegates to the module’s_author_values,_footer_values,_append_tag,_append_url_tag,_append_fields,_append_providerand_append_raw_fallbackhelpers; it performs no I/O and no mutation ofembed. Called byserialize_rich_content(for both top-level and forwarded-snapshot embeds) in this module, and exercised directly bytests/test_discord_rich_content.py; no other callers.
- platforms.discord_rich_content.serialize_rich_content(message)[source]
Convert a message’s embeds, snapshots, stickers and polls to text.
Walks every non-textual artifact attached to a Discord message and renders each into LLM-readable text so the model perceives the same rich content a human sees: embeds become
<embed>blocks, forwardedmessage_snapshotsbecome<forwarded_message>blocks (with their own nested content, embeds and attachments), stickers become[Sticker: name]lines, and a poll becomes a<poll>block listing its options. Parts are joined with newlines; a message with no rich content yields an empty string.Reads only attributes off
message(embeds,message_snapshots,stickers,poll) and delegates per-embed rendering toserialize_embed; it performs no I/O. Called bymerge_content_with_rich_contentin this module, by the Discord bot and selfbot adapters (platforms/discord.pyandplatforms/discord_self.pyimport it as_serialize_rich_contentto diff edited messages), and bytests/test_discord_rich_content.py.
- platforms.discord_rich_content.merge_content_with_rich_content(content, message)[source]
Combine a message’s plain text with its serialized rich content.
Produces the single text blob the rest of the pipeline stores and feeds to the LLM by appending the embeds/snapshots/stickers/polls rendering to the message’s plain
content(separated by a newline), so structured artifacts are not lost when a message is reduced to text. When there is no rich content the plain text is returned unchanged, and when there is no plain text only the rich content is returned.Stringifies
contentvia_as_textand obtains the rich portion fromserialize_rich_content; no I/O. Called wherever a Discord message is flattened to history/prompt text: the bot adapter (platforms/discord.py) and selfbot adapter (this package’splatforms/discord_self.py) on-message and history paths, the knowledge-graph builderbuild_kg.py, and thetools/discord_embed.pytool; also covered bytests/test_discord_rich_content.py.- Parameters:
- Returns:
The merged text, the plain text alone, or the rich content alone depending on which parts are present.
- Return type: