Skip to main content

Message

Struct Message 

Source
#[non_exhaustive]
pub struct Message {
Show 40 fields pub id: MessageId, pub channel_id: ChannelId, pub guild_id: Option<GuildId>, pub author: User, pub member: Option<Box<PartialMember>>, pub content: CompactString, pub timestamp: Timestamp, pub edited_timestamp: Option<Timestamp>, pub tts: bool, pub mention_everyone: bool, pub mentions: Vec<Mention>, pub mention_roles: Vec<RoleId>, pub mention_channels: Vec<ChannelMention>, pub attachments: Vec<Attachment>, pub embeds: Vec<Embed>, pub reactions: Vec<Reaction>, pub nonce: Option<Nonce>, pub pinned: bool, pub webhook_id: Option<WebhookId>, pub kind: MessageType, pub activity: Option<Box<MessageActivity>>, pub application: Option<Box<PartialApplication>>, pub application_id: Option<ApplicationId>, pub flags: MessageFlags, pub message_reference: Option<MessageReference>, pub message_snapshots: Vec<MessageSnapshot>, pub referenced_message: ReferencedMessage, pub interaction_metadata: Option<Box<InteractionMetadata>>, pub interaction: Option<Box<MessageInteraction>>, pub components: Vec<Component>, pub thread: Option<Box<Channel>>, pub resolved: Option<Box<Resolved>>, pub sticker_items: Vec<StickerItem>, pub stickers: Vec<Sticker>, pub position: Option<u32>, pub role_subscription_data: Option<Box<RoleSubscriptionData>>, pub poll: Option<Box<Poll>>, pub call: Option<Box<MessageCall>>, pub shared_client_theme: Option<Box<SharedClientTheme>>, pub channel_type: Option<ChannelType>,
}
Expand description

A message sent in a channel.

The same type is used for messages received through the gateway (MESSAGE_CREATE, MESSAGE_UPDATE) and from REST. The gateway adds a few fields (guild_id, member, the members of mentions, channel_type) that REST responses do not have.

Without the MESSAGE_CONTENT privileged intent, content, embeds and attachments are empty and poll is absent, except in DMs, in messages that mention the bot and in the bot’s own messages.

Rare sub-objects are boxed so a typical message stays small (D-054).

Contains floats (through Attachment), so it is PartialEq but not Eq (D-064).

discord.js counterpart: Message.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§id: MessageId

The message’s ID.

§channel_id: ChannelId

The ID of the channel the message was sent in.

§guild_id: Option<GuildId>

The ID of the guild the message was sent in (gateway only).

§author: User

The author of the message.

For webhook messages this is a pseudo-user built from the webhook’s ID, name and avatar (check webhook_id).

§member: Option<Box<PartialMember>>

The author’s member in the guild (gateway only, guild messages not sent by webhooks).

§content: CompactString

The text content of the message.

Empty without the MESSAGE_CONTENT privileged intent (see above).

§timestamp: Timestamp

When the message was sent.

§edited_timestamp: Option<Timestamp>

When the message was last edited, if ever.

§tts: bool

Whether this was a text-to-speech message (always false in MESSAGE_UPDATE).

§mention_everyone: bool

Whether the message mentions @everyone (or @here).

§mentions: Vec<Mention>

The users mentioned in the message, with their members in guild messages received through the gateway (D-060).

§mention_roles: Vec<RoleId>

The roles mentioned in the message.

§mention_channels: Vec<ChannelMention>

The channels mentioned in the message. Only channels visible to everyone in public guilds are listed, and currently only on crossposted messages.

§attachments: Vec<Attachment>

The attached files (except those referenced in embeds or components).

§embeds: Vec<Embed>

The embeds.

§reactions: Vec<Reaction>

The reactions.

§nonce: Option<Nonce>

The value the sender used to check that the message was sent.

§pinned: bool

Whether the message is pinned.

§webhook_id: Option<WebhookId>

If the message was generated by a webhook, the webhook’s ID.

§kind: MessageType

The kind of message.

§activity: Option<Box<MessageActivity>>

The Rich Presence activity of a Rich Presence chat embed.

§application: Option<Box<PartialApplication>>

The application of a Rich Presence chat embed.

§application_id: Option<ApplicationId>

The application of an interaction response or an application-owned webhook message.

§flags: MessageFlags

The message’s flags.

§message_reference: Option<MessageReference>

The source of a crosspost, channel follow, pin, reply, forward, … (see MessageReference).

§message_snapshots: Vec<MessageSnapshot>

The forwarded message(s), when message_reference is a forward.

§referenced_message: ReferencedMessage

The message this one replies to (or starts a thread from, or a context menu command was run on), for messages of type Reply, ThreadStarterMessage and ContextMenuCommand (D-061).

§interaction_metadata: Option<Box<InteractionMetadata>>

The interaction the message was sent for.

§interaction: Option<Box<MessageInteraction>>

The interaction the message responds to. Deprecated by Discord in favor of interaction_metadata.

§components: Vec<Component>

The components (buttons, select menus, or Components V2 layout with IS_COMPONENTS_V2). Empty without the MESSAGE_CONTENT privileged intent (see above).

§thread: Option<Box<Channel>>

The thread started from this message (with the current user’s thread member, if any).

§resolved: Option<Box<Resolved>>

The users, members, channels and roles referenced by the message’s components (Components V2 messages with select menu default values or mentions).

§sticker_items: Vec<StickerItem>

The stickers sent with the message.

§stickers: Vec<Sticker>

The full stickers sent with the message. Deprecated by Discord in favor of sticker_items.

§position: Option<u32>

The approximate position of the message in its thread: a generally increasing number (with possible gaps and duplicates) for messages in threads.

§role_subscription_data: Option<Box<RoleSubscriptionData>>

The role subscription purchase or renewal a RoleSubscriptionPurchase message announces.

§poll: Option<Box<Poll>>

The poll.

§call: Option<Box<MessageCall>>

The call a Call message is about.

§shared_client_theme: Option<Box<SharedClientTheme>>

A client theme shared through the message.

§channel_type: Option<ChannelType>

The type of the channel the message was sent in (gateway only).

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Message

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<MessageCreate> for Message

Source§

fn from(event: MessageCreate) -> Self

Converts to this type from the input type.
Source§

impl From<MessageUpdate> for Message

Source§

fn from(event: MessageUpdate) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Message

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Message

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Message

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.