Message is the full representation of a message. Created when MESSAGE_CREATE and MESSAGE_UPDATE events are received.
PartialMessage is a reduced version, available in MESSAGE_DELETE.
Message - Fields
| Field | Type | Description |
|---|---|---|
id | Snowflake | Unique message identifier. |
channel_id | Snowflake | ID of the channel the message belongs to. |
guild_id | Option<Snowflake> | Guild ID. None in DMs. |
author | User | Message author. |
content | String | Text content of the message. |
timestamp | String | Time sent (ISO 8601). |
edited_timestamp | Option<String> | Time of last edit. None if never edited. |
pinned | bool | Whether the message is pinned. |
tts | bool | Whether the message is TTS. |
mention_everyone | bool | Whether the message contains @everyone or @here. |
mentions | Vec<User> | Mentioned users. |
mention_roles | Vec<Snowflake> | IDs of mentioned roles. |
embeds | Vec<ApiEmbed> | Embedded rich content blocks. |
attachments | Vec<ApiMessageAttachment> | Attached files. |
stickers | Vec<ApiMessageSticker> | Attached stickers. |
reactions | Vec<ApiMessageReaction> | List of reactions. |
message_reference | Option<ApiMessageReference> | Reference to another message (for replies or forwards). |
referenced_message | Option<Box<Message>> | The message being replied to. May be absent even when message_reference is present. |
message_type | MessageType | Message type. |
flags | Option<u32> | Message bitfield flags. |
nonce | Option<String> | Arbitrary value for client-side message identification. |
webhook_id | Option<Snowflake> | Webhook ID if the message was sent via a webhook. |
member_data | Option<Value> | Raw JSON of member data from the event payload. |
PartialMessage - Fields
Available inDispatchEvent::MessageDelete.
| Field | Type | Description |
|---|---|---|
id | Snowflake | ID of the deleted message. |
channel_id | Snowflake | Channel ID. |
guild_id | Option<Snowflake> | Guild ID. None in DMs. |
content | Option<String> | Content, if it was cached. |
author_id | Option<Snowflake> | Author ID, if it was cached. |
Constructors
Message::from_api
Message from a deserialized API response.
Message::from_value
Message from a serde_json::Value. Additionally stores the member field in member_data if present in the payload. Returns None on deserialization failure.
Methods
Sending
send
Example
Example
send_files
FileAttachment.
send_to
Replies
reply
message_reference is set automatically.
Example
Example
reply_with
MessagePayloadData. The message_reference field is set automatically - no need to fill it manually.
reply_with_files
message_reference is set automatically.
Example: reply with an embed
Example: reply with an embed
Edit and delete
edit
Example: send and edit after a delay
Example: send and edit after a delay
delete
fetch
channel_id and id.
Reactions
add_reaction
"👍"). For custom emoji: "name:id".
remove_reaction
remove_user_reaction
MANAGE_MESSAGES.
remove_all_reactions
MANAGE_MESSAGES.
remove_reaction_emoji
fetch_reaction_users
| Parameter | Description |
|---|---|
emoji | Unicode character or "name:id" for custom emoji. |
limit | Maximum number of users (1–100). |
after | Pagination: return users after this ID. |
Example: add a reaction and remove it after a delay
Example: add a reaction and remove it after a delay
Example: fetch users who reacted
Example: fetch users who reacted
Pinning
pin / unpin
MANAGE_MESSAGES.
Attachments
delete_attachment
Helpers
mention_author
<@user_id>.
MessageType
Message type, available in themessage_type field.
| Value | Description |
|---|---|
Default | Regular user or bot message. |
RecipientAdd | User added to a group DM. |
RecipientRemove | User removed from a group DM. |
Call | System message about a call. |
ChannelNameChange | Channel name was changed. |
ChannelIconChange | Channel icon was changed. |
ChannelPinnedMessage | A message was pinned. |
GuildMemberJoin | A new member joined the guild. |
Reply | A reply to a message. |
A
Reply type does not guarantee that referenced_message is populated. The original message may have been deleted.