MessagePayload is a builder pattern for constructing MessagePayloadData. Used in all message sending methods: channel.send, message.reply, message.edit, etc.
MessagePayloadData
The final structure passed to REST methods. All fields are optional during serialization - missing fields are not included in JSON.| Field | Type | Description |
|---|---|---|
content | Option<String> | Text content. Maximum 2000 characters. |
embeds | Option<Vec<ApiEmbed>> | List of embed blocks. Maximum 10. |
attachments | Option<Vec<AttachmentPayload>> | Attachment metadata. Populated automatically when sending files. |
message_reference | Option<ApiMessageReference> | Reference to a message for a reply. |
tts | Option<bool> | Send as a TTS message. |
flags | Option<u32> | Message bitfield flags. |
MessagePayloadData implements Serialize and Deserialize, so it can be stored, cloned, and passed around like a regular data structure.MessagePayload
Builder forMessagePayloadData. All methods take self and return Self - method chaining is supported.
Creating
MessagePayload::new
MessagePayload::from_content
content already set. Equivalent to MessagePayload::new().content(content).
Methods
content
embeds
add_embed
add_embed_builder
.build() on the given EmbedBuilder and appends the result. Convenient for inline chaining without an intermediate variable.
Example: message with text and an embed
Example: message with text and an embed
attachments
send_files.
reply
message_reference to reply to a specific message.
When using
message.reply() and message.reply_with(), the message_reference field is set automatically - calling reply() manually is not needed.Example: manually set a reply reference
Example: manually set a reply reference
tts
true, the message is read aloud via TTS for all channel members who have TTS enabled.
flags
attach_file
build_with_files or build_form.
attach_files
Finalizing
build
MessagePayloadData. Files added via attach_file are not included in the result - use build_with_files or build_form to send with files.
build_with_files
MessagePayloadData and the file list separately. Use together with rest.post_multipart.
build_form
multipart::Form for direct passing to rest.post_multipart. Includes payload_json and all attached files.
has_files
true if at least one file has been attached to the builder.
AttachmentPayload
Attachment metadata. Generated automatically insidebuild_multipart_form.
| Field | Type | Description |
|---|---|---|
id | u32 | Sequential file index (0, 1, 2, …). |
filename | String | File name in the request. For spoilers, the SPOILER_ prefix is added. |
description | Option<String> | Attachment description (displayed as alt text). |
Examples
Message with text only
Message with text only
Multiple embed blocks
Multiple embed blocks
Send with a file
Send with a file
Reply with an embed using reply_with
Reply with an embed using reply_with
