#[non_exhaustive]
pub struct Message {
Show 28 fields pub id: MessageId, pub attachments: Vec<Attachment>, pub author: User, pub channel_id: ChannelId, pub content: String, pub edited_timestamp: Option<Timestamp>, pub embeds: Vec<Embed>, pub guild_id: Option<GuildId>, pub kind: MessageType, pub member: Option<PartialMember>, pub mention_everyone: bool, pub mention_roles: Vec<RoleId>, pub mention_channels: Vec<ChannelMention>, pub mentions: Vec<User>, pub nonce: Value, pub pinned: bool, pub reactions: Vec<MessageReaction>, pub timestamp: Timestamp, pub tts: bool, pub webhook_id: Option<WebhookId>, pub activity: Option<MessageActivity>, pub application: Option<MessageApplication>, pub message_reference: Option<MessageReference>, pub flags: Option<MessageFlags>, pub sticker_items: Vec<StickerItem>, pub referenced_message: Option<Box<Message>>, pub interaction: Option<MessageInteraction>, pub components: Vec<ActionRow>,
}
Expand description

A representation of a message over a guild’s text channel, a group, or a private channel.

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 unique Id of the message. Can be used to calculate the creation date of the message.

attachments: Vec<Attachment>

An vector of the files attached to a message.

author: User

The user that sent the message.

channel_id: ChannelId

The Id of the Channel that the message was sent to.

content: String

The content of the message.

edited_timestamp: Option<Timestamp>

The timestamp of the last time the message was updated, if it was.

embeds: Vec<Embed>

Array of embeds sent with the message.

guild_id: Option<GuildId>

The Id of the Guild that the message was sent in. This value will only be present if this message was received over the gateway.

kind: MessageType

Indicator of the type of message this is, i.e. whether it is a regular message or a system message.

member: Option<PartialMember>

A partial amount of data about the user’s member data, if this message was sent in a guild.

mention_everyone: bool

Indicator of whether the message mentions everyone.

mention_roles: Vec<RoleId>

Array of Roles’ Ids mentioned in the message.

mention_channels: Vec<ChannelMention>

Channels specifically mentioned in this message.

Note: Not all channel mentions in a message will appear in Self::mention_channels. Only textual channels that are visible to everyone in a lurkable guild will ever be included.

A lurkable guild is one that allows users to read public channels in a server without actually joining the server. It also allows users to look at these channels without being logged in to Discord.

Only crossposted messages (via Channel Following) currently include Self::mention_channels at all. If no mentions in the message meet these requirements, this field will not be sent. Refer to Discord’s documentation for more information.

mentions: Vec<User>

Array of users mentioned in the message.

nonce: Value

Non-repeating number used for ensuring message order.

pinned: bool

Indicator of whether the message is pinned.

reactions: Vec<MessageReaction>

Array of reactions performed on the message.

timestamp: Timestamp

Initial message creation timestamp, calculated from its Id.

tts: bool

Indicator of whether the command is to be played back via text-to-speech.

In the client, this is done via the /tts slash command.

webhook_id: Option<WebhookId>

The Id of the webhook that sent this message, if one did.

activity: Option<MessageActivity>

Sent with Rich Presence-related chat embeds.

application: Option<MessageApplication>

Sent with Rich Presence-related chat embeds.

message_reference: Option<MessageReference>

Reference data sent with crossposted messages.

flags: Option<MessageFlags>

Bit flags describing extra features of the message.

sticker_items: Vec<StickerItem>

Array of message sticker item objects.

referenced_message: Option<Box<Message>>

The message that was replied to using this message.

interaction: Option<MessageInteraction>

Sent if the message is a response to an Interaction.

components: Vec<ActionRow>

The components of this message

Implementations

Available on crate feature model only.

Crossposts this message.

Requires either to be the message author or to have manage Manage Messages permissions on this channel.

Note: Only available on news channels.

Errors

If the cache is enabled, returns a ModelError::InvalidPermissions if the current user does not have the required permissions.

Returns a ModelError::MessageAlreadyCrossposted if the message has already been crossposted.

Returns a ModelError::CannotCrosspostMessage if the message cannot be crossposted.

Available on crate feature model only.

First attempts to find a Channel by its Id in the cache, upon failure requests it via the REST API.

Note: If the cache-feature is enabled permissions will be checked and upon owning the required permissions the HTTP-request will be issued.

Errors

Can return an error if the HTTP request fails.

Available on crate features model and cache only.

A util function for determining whether this message was sent by someone else, or the bot.

Available on crate feature model only.

Deletes the message.

Note: The logged in user must either be the author of the message or have the Manage Messages permission.

Errors

If the cache feature is enabled, then returns a ModelError::InvalidPermissions if the current user does not have the required permissions.

Available on crate feature model only.

Deletes all of the Reactions associated with the message.

Note: Requires the Manage Messages permission.

Errors

If the cache feature is enabled, then returns a ModelError::InvalidPermissions if the current user does not have the required permissions.

Available on crate feature model only.

Deletes all of the Reactions of a given emoji associated with the message.

Note: Requires the Manage Messages permission.

Errors

If the cache feature is enabled, then returns a ModelError::InvalidPermissions if the current user does not have the required permissions.

Available on crate feature model only.

Edits this message, replacing the original content with new content.

Message editing preserves all unchanged message data.

Refer to the documentation for EditMessage for more information regarding message restrictions and requirements.

Note: Requires that the current user be the author of the message.

Examples

Edit a message with new content:

// assuming a `message` has already been bound

message.edit(&context, |m| m.content("new content"));
Errors

If the cache is enabled, returns a ModelError::InvalidUser if the current user is not the author.

Returns a ModelError::MessageTooLong if the content of the message is over the limit, containing the number of unicode code points over the limit.

Available on crate features model and cache only.

Returns message content, but with user and role mentions replaced with names and everyone/here mentions cancelled.

Available on crate feature model only.

Gets the list of Users who have reacted to a Message with a certain Emoji.

The default limit is 50 - specify otherwise to receive a different maximum number of users. The maximum that may be retrieve at a time is 100, if a greater number is provided then it is automatically reduced.

The optional after attribute is to retrieve the users after a certain user. This is useful for pagination.

Note: Requires the Read Message History permission.

Errors

Returns Error::Http if the current user lacks permission.

Available on crate features model and cache only.

Returns the associated Guild for the message if one is in the cache.

Returns None if the guild’s Id could not be found via Self::guild_id or if the Guild itself is not cached.

Requires the cache feature be enabled.

Available on crate features model and cache only.

Returns a field to the Guild for the message if one is in the cache. The field can be selected via the field_accessor.

Returns None if the guild’s ID could not be found via Self::guild_id or if the Guild itself is not cached.

Requires the cache feature be enabled.

Available on crate feature model only.

True if message was sent using direct messages.

Available on crate feature model only.

Retrieves a clone of the author’s Member instance, if this message was sent in a guild.

If the instance cannot be found in the cache, or the cache feature is disabled, a HTTP request is performed to retrieve it from Discord’s API.

Errors

ModelError::ItemMissing is returned if Self::guild_id is None.

Available on crate feature model only.

Checks the length of a string to ensure that it is within Discord’s maximum message length limit.

Returns None if the message is within the limit, otherwise returns Some with an inner value of how many unicode code points the message is over.

Available on crate feature model only.

Pins this message to its channel.

Note: Requires the Manage Messages permission.

Errors

If the cache is enabled, returns a ModelError::InvalidPermissions if the current user does not have the required permissions.

Available on crate feature model only.

React to the message with a custom Emoji or unicode character.

Note: Requires the Add Reactions permission.

Errors

If the cache is enabled, returns a ModelError::InvalidPermissions if the current user does not have the required permissions.

Available on crate feature model only.

Uses Discord’s inline reply to a user without pinging them.

User mentions are generally around 20 or 21 characters long.

Note: Requires the Send Messages permission.

Note: Message contents must be under 2000 unicode code points.

Errors

If the cache is enabled, returns a ModelError::InvalidPermissions if the current user does not have the required permissions.

Returns a ModelError::MessageTooLong if the content of the message is over the above limit, containing the number of unicode code points over the limit.

Available on crate feature model only.

Uses Discord’s inline reply to a user with a ping.

Note: Requires the Send Messages permission.

Note: Message contents must be under 2000 unicode code points.

Errors

If the cache is enabled, returns a ModelError::InvalidPermissions if the current user does not have the required permissions.

Returns a ModelError::MessageTooLong if the content of the message is over the above limit, containing the number of unicode code points over the limit.

Available on crate feature model only.

Replies to the user, mentioning them prior to the content in the form of: @<USER_ID> YOUR_CONTENT.

User mentions are generally around 20 or 21 characters long.

Note: Requires the Send Messages permission.

Note: Message contents must be under 2000 unicode code points.

Errors

If the cache is enabled, returns a ModelError::InvalidPermissions if the current user does not have the required permissions.

Returns a ModelError::MessageTooLong if the content of the message is over the above limit, containing the number of unicode code points over the limit.

Available on crate feature model only.

Delete all embeds in this message Note: The logged in user must either be the author of the message or have the Manage Messages permission.

Errors

If the cache feature is enabled, then returns a ModelError::InvalidPermissions if the current user does not have the required permissions.

Otherwise returns Error::Http if the current user lacks permission.

Available on crate feature model only.

Checks whether the message mentions passed UserId.

Available on crate feature model only.

Checks whether the message mentions passed User.

Available on crate feature model only.

Checks whether the message mentions the current user.

Errors

May return Error::Http if the cache feature is not enabled, or if the cache is otherwise unavailable.

Available on crate feature model only.

Unpins the message from its channel.

Note: Requires the Manage Messages permission.

Errors

If the cache is enabled, returns a ModelError::InvalidPermissions if the current user does not have the required permissions.

Available on crate feature model only.

Tries to return author’s nickname in the current channel’s guild.

Refer to User::nick_in() inside and None outside of a guild.

Available on crate feature model only.

Returns a link referencing this message. When clicked, users will jump to the message. The link will be valid for messages in either private channels or guilds.

Available on crate feature model only.

Same as Self::link but tries to find the GuildId if Discord does not provide it.

Available on crate features model and collector only.

Await a single reaction on this message.

Available on crate features model and collector only.

Returns a stream builder which can be awaited to obtain a stream of reactions on this message.

Available on crate features model and collector only.

Await a single component interaction on this message.

Available on crate features model and collector only.

Returns a stream builder which can be awaited to obtain a stream of component interactions on this message.

Available on crate features model and collector only.

Await a single modal submit interaction on this message.

Available on crate features model and collector only.

Returns a stream builder which can be awaited to obtain a stream of modal submit interactions on this message.

Available on crate features model and cache only.

Retrieves the message channel’s category ID if the channel has one.

Trait Implementations

Look up a message by a string.

The lookup strategy is as follows (in order):

  1. Lookup by “{channel ID}-{message ID}” (retrieved by shift-clicking on “Copy ID”)
  2. Lookup by message ID (the message must be in the context channel)
  3. Lookup by message URL
Available on crate features utils and client only.

The associated error which can be returned from parsing.

Available on crate features utils and client only.

Parses a string s as a command parameter of this type.

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Gets the Id of a Message.

Converts to this type from the input type.

Gets the Id of a Message.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

Should always be Self

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more