#[non_exhaustive]pub struct Message {Show 34 fields
pub id: MessageId,
pub channel_id: ChannelId,
pub author: User,
pub content: String,
pub timestamp: Timestamp,
pub edited_timestamp: Option<Timestamp>,
pub tts: bool,
pub mention_everyone: bool,
pub mentions: Vec<User>,
pub mention_roles: Vec<RoleId>,
pub mention_channels: Vec<ChannelMention>,
pub attachments: Vec<Attachment>,
pub embeds: Vec<Embed>,
pub reactions: Vec<MessageReaction>,
pub nonce: Option<Nonce>,
pub pinned: bool,
pub webhook_id: Option<WebhookId>,
pub kind: MessageType,
pub activity: Option<MessageActivity>,
pub application: Option<MessageApplication>,
pub application_id: Option<ApplicationId>,
pub message_reference: Option<MessageReference>,
pub flags: Option<MessageFlags>,
pub referenced_message: Option<Box<Message>>,
pub interaction: Option<Box<MessageInteraction>>,
pub interaction_metadata: Option<Box<MessageInteractionMetadata>>,
pub thread: Option<GuildChannel>,
pub components: Vec<ActionRow>,
pub sticker_items: Vec<StickerItem>,
pub position: Option<u64>,
pub role_subscription_data: Option<RoleSubscriptionData>,
pub guild_id: Option<GuildId>,
pub member: Option<Box<PartialMember>>,
pub poll: Option<Box<Poll>>,
}
Expand description
A representation of a message over a guild’s text channel, a group, or a private channel.
Discord docs with some extra fields.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
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.
channel_id: ChannelId
The Id of the Channel
that the message was sent to.
The user that sent the message.
content: String
The content of the message.
timestamp: Timestamp
Initial message creation timestamp, calculated from its Id.
edited_timestamp: Option<Timestamp>
The timestamp of the last time the message was updated, if it was.
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.
mention_everyone: bool
Indicator of whether the message mentions everyone.
mentions: Vec<User>
Array of users mentioned in the message.
mention_roles: Vec<RoleId>
Array of Role
s’ 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.
attachments: Vec<Attachment>
An vector of the files attached to a message.
embeds: Vec<Embed>
Array of embeds sent with the message.
reactions: Vec<MessageReaction>
Array of reactions performed on the message.
nonce: Option<Nonce>
Non-repeating number used for ensuring message order.
pinned: bool
Indicator of whether the message is pinned.
webhook_id: Option<WebhookId>
The Id of the webhook that sent this message, if one did.
kind: MessageType
Indicator of the type of message this is, i.e. whether it is a regular message or a system message.
activity: Option<MessageActivity>
Sent with Rich Presence-related chat embeds.
application: Option<MessageApplication>
Sent with Rich Presence-related chat embeds.
application_id: Option<ApplicationId>
If the message is an Interaction or application-owned webhook, this is the id of the application.
message_reference: Option<MessageReference>
Reference data sent with crossposted messages.
flags: Option<MessageFlags>
Bit flags describing extra features of the message.
referenced_message: Option<Box<Message>>
The message that was replied to using this message.
interaction: Option<Box<MessageInteraction>>
interaction_metadata: Option<Box<MessageInteractionMetadata>>
Sent if the message is a response to an Interaction
.
thread: Option<GuildChannel>
The thread that was started from this message, includes thread member object.
components: Vec<ActionRow>
The components of this message
sticker_items: Vec<StickerItem>
Array of message sticker item objects.
position: Option<u64>
A generally increasing integer (there may be gaps or duplicates) that represents the approximate position of the message in a thread, it can be used to estimate the relative position of the message in a thread in company with total_message_sent on parent thread.
role_subscription_data: Option<RoleSubscriptionData>
Data of the role subscription purchase or renewal that prompted this
MessageType::RoleSubscriptionPurchase
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, therefore do not use this to check if message
is in DMs, it is not a reliable method.
member: Option<Box<PartialMember>>
A partial amount of data about the user’s member data
Only present in MessageCreateEvent
.
poll: Option<Box<Poll>>
A poll that may be attached to a message.
This is often omitted, so is boxed to improve memory usage.
Only present in MessageCreateEvent
.
Implementations§
Source§impl Message
impl Message
Sourcepub async fn crosspost(&self, cache_http: impl CacheHttp) -> Result<Message>
pub async fn crosspost(&self, cache_http: impl CacheHttp) -> Result<Message>
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.
Sourcepub fn is_own(&self, cache: impl AsRef<Cache>) -> bool
👎Deprecated: Check Message::author is equal to Cache::current_user
pub fn is_own(&self, cache: impl AsRef<Cache>) -> bool
A util function for determining whether this message was sent by someone else, or the bot.
Calculates the permissions of the message author in the current channel.
This handles the Permissions::SEND_MESSAGES_IN_THREADS
permission for threads, setting
Permissions::SEND_MESSAGES
accordingly if this message was sent in a thread.
This may return None
if:
Sourcepub async fn delete(&self, cache_http: impl CacheHttp) -> Result<()>
pub async fn delete(&self, cache_http: impl CacheHttp) -> Result<()>
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.
Sourcepub async fn delete_reactions(&self, cache_http: impl CacheHttp) -> Result<()>
pub async fn delete_reactions(&self, cache_http: impl CacheHttp) -> Result<()>
Deletes all of the Reaction
s 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.
Sourcepub async fn delete_reaction(
&self,
http: impl AsRef<Http>,
user_id: Option<UserId>,
reaction_type: impl Into<ReactionType>,
) -> Result<()>
pub async fn delete_reaction( &self, http: impl AsRef<Http>, user_id: Option<UserId>, reaction_type: impl Into<ReactionType>, ) -> Result<()>
Deletes the given Reaction
from the message.
Note: Requires the Manage Messages permission, if the current user did not perform the reaction.
§Errors
Returns Error::Http
if the current user did not perform the reaction, or lacks
permission.
Sourcepub async fn delete_reaction_emoji(
&self,
cache_http: impl CacheHttp,
reaction_type: impl Into<ReactionType>,
) -> Result<()>
pub async fn delete_reaction_emoji( &self, cache_http: impl CacheHttp, reaction_type: impl Into<ReactionType>, ) -> Result<()>
Deletes all of the Reaction
s 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.
Sourcepub async fn edit(
&mut self,
cache_http: impl CacheHttp,
builder: EditMessage,
) -> Result<()>
pub async fn edit( &mut self, cache_http: impl CacheHttp, builder: EditMessage, ) -> Result<()>
Edits this message, replacing the original content with new content.
Message editing preserves all unchanged message data, with some exceptions for embeds and attachments.
Note: In most cases requires that the current user be the author of the message.
Refer to the documentation for EditMessage
for information regarding content
restrictions and requirements.
§Examples
Edit a message with new content:
// assuming a `message` has already been bound
let builder = EditMessage::new().content("new content");
message.edit(&http, builder).await?;
§Errors
If the cache
is enabled, returns a ModelError::InvalidUser
if the current user is not
the author. Otherwise returns Error::Http
if the user lacks permission, as well as if
invalid data is given.
Returns a ModelError::MessageTooLong
if the message contents are too long.
Sourcepub fn content_safe(&self, cache: impl AsRef<Cache>) -> String
pub fn content_safe(&self, cache: impl AsRef<Cache>) -> String
Returns message content, but with user and role mentions replaced with names and everyone/here mentions cancelled.
Sourcepub async fn reaction_users(
&self,
http: impl AsRef<Http>,
reaction_type: impl Into<ReactionType>,
limit: Option<u8>,
after: impl Into<Option<UserId>>,
) -> Result<Vec<User>>
pub async fn reaction_users( &self, http: impl AsRef<Http>, reaction_type: impl Into<ReactionType>, limit: Option<u8>, after: impl Into<Option<UserId>>, ) -> Result<Vec<User>>
Gets the list of User
s 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.
Note: If the passed reaction_type is a custom guild emoji, it must contain the name.
So, Emoji
or EmojiIdentifier
will always work, ReactionType
only if
ReactionType::Custom::name
is Some, and EmojiId
will never work.
§Errors
Returns Error::Http
if the current user lacks permission.
Sourcepub fn guild<'a>(&self, cache: &'a Cache) -> Option<GuildRef<'a>>
pub fn guild<'a>(&self, cache: &'a Cache) -> Option<GuildRef<'a>>
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.
Sourcepub fn is_private(&self) -> bool
👎Deprecated: Check if guild_id is None if the message is received from the gateway.
pub fn is_private(&self) -> bool
True if message was sent using direct messages.
Only use this for messages from the gateway (event handler)! Not for returned Message
objects from HTTP requests, like ChannelId::send_message
, because Self::guild_id
is
never set for those, which this method relies on.
Sourcepub async fn member(&self, cache_http: impl CacheHttp) -> Result<Member>
pub async fn member(&self, cache_http: impl CacheHttp) -> Result<Member>
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
.
Sourcepub fn overflow_length(content: &str) -> Option<usize>
pub fn overflow_length(content: &str) -> Option<usize>
Sourcepub async fn pin(&self, cache_http: impl CacheHttp) -> Result<()>
pub async fn pin(&self, cache_http: impl CacheHttp) -> Result<()>
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.
Sourcepub async fn react(
&self,
cache_http: impl CacheHttp,
reaction_type: impl Into<ReactionType>,
) -> Result<Reaction>
pub async fn react( &self, cache_http: impl CacheHttp, reaction_type: impl Into<ReactionType>, ) -> Result<Reaction>
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.
Sourcepub async fn super_react(
&self,
cache_http: impl CacheHttp,
reaction_type: impl Into<ReactionType>,
) -> Result<Reaction>
pub async fn super_react( &self, cache_http: impl CacheHttp, reaction_type: impl Into<ReactionType>, ) -> Result<Reaction>
React to the message with a custom Emoji
or unicode character.
Note: Requires Add Reactions and Use External Emojis permissions.
§Errors
If the cache
is enabled, returns a ModelError::InvalidPermissions
if the current user
does not have the required permissions.
Sourcepub async fn reply(
&self,
cache_http: impl CacheHttp,
content: impl Into<String>,
) -> Result<Message>
pub async fn reply( &self, cache_http: impl CacheHttp, content: impl Into<String>, ) -> Result<Message>
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.
Sourcepub async fn reply_ping(
&self,
cache_http: impl CacheHttp,
content: impl Into<String>,
) -> Result<Message>
pub async fn reply_ping( &self, cache_http: impl CacheHttp, content: impl Into<String>, ) -> Result<Message>
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.
Sourcepub async fn reply_mention(
&self,
cache_http: impl CacheHttp,
content: impl Display,
) -> Result<Message>
pub async fn reply_mention( &self, cache_http: impl CacheHttp, content: impl Display, ) -> Result<Message>
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.
Sourcepub fn mentions_user_id(&self, id: impl Into<UserId>) -> bool
pub fn mentions_user_id(&self, id: impl Into<UserId>) -> bool
Checks whether the message mentions passed UserId
.
Sourcepub fn mentions_user(&self, user: &User) -> bool
pub fn mentions_user(&self, user: &User) -> bool
Checks whether the message mentions passed User
.
Sourcepub async fn mentions_me(&self, cache_http: impl CacheHttp) -> Result<bool>
pub async fn mentions_me(&self, cache_http: impl CacheHttp) -> Result<bool>
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.
Sourcepub async fn unpin(&self, cache_http: impl CacheHttp) -> Result<()>
pub async fn unpin(&self, cache_http: impl CacheHttp) -> Result<()>
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.
Sourcepub async fn end_poll(&self, http: impl AsRef<Http>) -> Result<Self>
pub async fn end_poll(&self, http: impl AsRef<Http>) -> Result<Self>
Ends the Poll
on this message, if there is one.
§Errors
See ChannelId::end_poll
for more information.
Tries to return author’s nickname in the current channel’s guild.
Refer to User::nick_in()
inside and None
outside of a guild.
Sourcepub fn link(&self) -> String
pub fn link(&self) -> String
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.
Sourcepub async fn link_ensured(&self, cache_http: impl CacheHttp) -> String
👎Deprecated: Use Self::link if Message was recieved via an event, otherwise use MessageId::link to provide the guild_id yourself.
pub async fn link_ensured(&self, cache_http: impl CacheHttp) -> String
Same as Self::link
but tries to find the GuildId
if Discord does not provide it.
Sourcepub fn await_reaction(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> ReactionCollector
pub fn await_reaction( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ReactionCollector
Returns a builder which can be awaited to obtain a reaction or stream of reactions on this message.
Sourcepub fn await_reactions(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> ReactionCollector
pub fn await_reactions( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ReactionCollector
Same as Self::await_reaction
.
Sourcepub fn await_component_interaction(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> ComponentInteractionCollector
pub fn await_component_interaction( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ComponentInteractionCollector
Returns a builder which can be awaited to obtain a single component interactions or a stream of component interactions on this message.
Sourcepub fn await_component_interactions(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> ComponentInteractionCollector
pub fn await_component_interactions( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ComponentInteractionCollector
Same as Self::await_component_interaction
.
Sourcepub fn await_modal_interaction(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> ModalInteractionCollector
pub fn await_modal_interaction( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ModalInteractionCollector
Returns a builder which can be awaited to obtain a model submit interaction or stream of modal submit interactions on this message.
Sourcepub fn await_modal_interactions(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> ModalInteractionCollector
pub fn await_modal_interactions( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ModalInteractionCollector
Same as Self::await_modal_interaction
.
Sourcepub async fn category_id(&self, cache_http: impl CacheHttp) -> Option<ChannelId>
pub async fn category_id(&self, cache_http: impl CacheHttp) -> Option<ChannelId>
Retrieves the message channel’s category ID if the channel has one.
Trait Implementations§
Source§impl ArgumentConvert for Message
Look up a message by a string.
impl ArgumentConvert for Message
Look up a message by a string.
The lookup strategy is as follows (in order):
- Lookup by “{channel ID}-{message ID}” (retrieved by shift-clicking on “Copy ID”)
- Lookup by message ID (the message must be in the context channel)
- Lookup by message URL
Source§type Err = MessageParseError
type Err = MessageParseError
Source§fn convert<'life0, 'async_trait>(
ctx: impl 'async_trait + CacheHttp,
_guild_id: Option<GuildId>,
channel_id: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Err>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn convert<'life0, 'async_trait>(
ctx: impl 'async_trait + CacheHttp,
_guild_id: Option<GuildId>,
channel_id: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Err>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
s
as a command parameter of this type.