Skip to main content
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

FieldTypeDescription
idSnowflakeUnique message identifier.
channel_idSnowflakeID of the channel the message belongs to.
guild_idOption<Snowflake>Guild ID. None in DMs.
authorUserMessage author.
contentStringText content of the message.
timestampStringTime sent (ISO 8601).
edited_timestampOption<String>Time of last edit. None if never edited.
pinnedboolWhether the message is pinned.
ttsboolWhether the message is TTS.
mention_everyoneboolWhether the message contains @everyone or @here.
mentionsVec<User>Mentioned users.
mention_rolesVec<Snowflake>IDs of mentioned roles.
embedsVec<ApiEmbed>Embedded rich content blocks.
attachmentsVec<ApiMessageAttachment>Attached files.
stickersVec<ApiMessageSticker>Attached stickers.
reactionsVec<ApiMessageReaction>List of reactions.
message_referenceOption<ApiMessageReference>Reference to another message (for replies or forwards).
referenced_messageOption<Box<Message>>The message being replied to. May be absent even when message_reference is present.
message_typeMessageTypeMessage type.
flagsOption<u32>Message bitfield flags.
nonceOption<String>Arbitrary value for client-side message identification.
webhook_idOption<Snowflake>Webhook ID if the message was sent via a webhook.
member_dataOption<Value>Raw JSON of member data from the event payload.

PartialMessage - Fields

Available in DispatchEvent::MessageDelete.
FieldTypeDescription
idSnowflakeID of the deleted message.
channel_idSnowflakeChannel ID.
guild_idOption<Snowflake>Guild ID. None in DMs.
contentOption<String>Content, if it was cached.
author_idOption<Snowflake>Author ID, if it was cached.

Constructors

Message::from_api

pub fn from_api(data: &ApiMessage) -> Self
Creates a Message from a deserialized API response.

Message::from_value

pub fn from_value(data: &Value) -> Option<Self>
Deserializes a 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

pub async fn send(
    &self,
    rest: &Rest,
    body: &MessagePayloadData,
) -> crate::Result<ApiMessage>
Sends a new message to the same channel as the current message.
let payload = MessagePayload::new()
    .content("Received!")
    .build();

let sent = message.send(&rest, &payload).await?;
println!("Sent: {}", sent.id);

send_files

pub async fn send_files(
    &self,
    rest: &Rest,
    body: &MessagePayloadData,
    files: &[FileAttachment],
) -> crate::Result<ApiMessage>
Sends a message with files to the same channel via multipart/form-data. See Files for details on FileAttachment.

send_to

pub async fn send_to(
    &self,
    rest: &Rest,
    channel_id: &str,
    body: &MessagePayloadData,
) -> crate::Result<ApiMessage>
Sends a message to an arbitrary channel by ID.

Replies

reply

pub async fn reply(
    &self,
    rest: &Rest,
    content: &str,
) -> crate::Result<ApiMessage>
Replies to the message with the given text. message_reference is set automatically.
message.reply(&rest, "Got it!").await?;

reply_with

pub async fn reply_with(
    &self,
    rest: &Rest,
    body: &MessagePayloadData,
) -> crate::Result<ApiMessage>
Replies with an arbitrary MessagePayloadData. The message_reference field is set automatically - no need to fill it manually.

reply_with_files

pub async fn reply_with_files(
    &self,
    rest: &Rest,
    body: &MessagePayloadData,
    files: &[FileAttachment],
) -> crate::Result<ApiMessage>
Replies with files. message_reference is set automatically.
let embed = EmbedBuilder::new()
    .title("Result")
    .description("Operation completed.")
    .color(0x57F287)
    .build();

let payload = MessagePayload::new().add_embed(embed).build();
message.reply_with(&rest, &payload).await?;

Edit and delete

edit

pub async fn edit(
    &self,
    rest: &Rest,
    body: &MessagePayloadData,
) -> crate::Result<ApiMessage>
Edits the current message. Bots can only edit their own messages.
let payload = MessagePayload::new().content("Loading...").build();
let msg = channel.send(&rest, &payload).await?;

tokio::time::sleep(std::time::Duration::from_secs(3)).await;

let edited_payload = MessagePayload::new().content("Done!").build();
msg.edit(&rest, &edited_payload).await?;

delete

pub async fn delete(&self, rest: &Rest) -> crate::Result<()>
Deletes the message.

fetch

pub async fn fetch(&self, rest: &Rest) -> crate::Result<ApiMessage>
Fetches the current message data from the API using channel_id and id.

Reactions

add_reaction

pub async fn add_reaction(&self, rest: &Rest, emoji: &str) -> crate::Result<()>
Adds a reaction from the bot. For Unicode: pass the character ("👍"). For custom emoji: "name:id".

remove_reaction

pub async fn remove_reaction(&self, rest: &Rest, emoji: &str) -> crate::Result<()>
Removes the bot’s own reaction.

remove_user_reaction

pub async fn remove_user_reaction(
    &self,
    rest: &Rest,
    emoji: &str,
    user_id: &str,
) -> crate::Result<()>
Removes a specific user’s reaction. Requires MANAGE_MESSAGES.

remove_all_reactions

pub async fn remove_all_reactions(&self, rest: &Rest) -> crate::Result<()>
Removes all reactions with all emoji. Requires MANAGE_MESSAGES.

remove_reaction_emoji

pub async fn remove_reaction_emoji(&self, rest: &Rest, emoji: &str) -> crate::Result<()>
Removes all reactions for a specific emoji.

fetch_reaction_users

pub async fn fetch_reaction_users(
    &self,
    rest: &Rest,
    emoji: &str,
    limit: Option<u32>,
    after: Option<&str>,
) -> crate::Result<Vec<ApiUser>>
Returns the list of users who reacted with the specified emoji.
ParameterDescription
emojiUnicode character or "name:id" for custom emoji.
limitMaximum number of users (1–100).
afterPagination: return users after this ID.
message.add_reaction(&rest, "👍").await?;

tokio::time::sleep(std::time::Duration::from_secs(5)).await;

message.remove_reaction(&rest, "👍").await?;
let users = message.fetch_reaction_users(&rest, "👍", Some(25), None).await?;
for user in &users {
    println!("{}", user.username);
}

Pinning

pin / unpin

pub async fn pin(&self, rest: &Rest) -> crate::Result<()>
pub async fn unpin(&self, rest: &Rest) -> crate::Result<()>
Pins or unpins the message in the channel. Requires MANAGE_MESSAGES.

Attachments

delete_attachment

pub async fn delete_attachment(
    &self,
    rest: &Rest,
    attachment_id: &str,
) -> crate::Result<()>
Deletes a specific attachment from the message.

Helpers

mention_author

pub fn mention_author(&self) -> String
Returns the author mention string in the format <@user_id>.

MessageType

Message type, available in the message_type field.
ValueDescription
DefaultRegular user or bot message.
RecipientAddUser added to a group DM.
RecipientRemoveUser removed from a group DM.
CallSystem message about a call.
ChannelNameChangeChannel name was changed.
ChannelIconChangeChannel icon was changed.
ChannelPinnedMessageA message was pinned.
GuildMemberJoinA new member joined the guild.
ReplyA reply to a message.
A Reply type does not guarantee that referenced_message is populated. The original message may have been deleted.