Struct serenity::model::Message
[−]
[src]
pub struct Message { pub id: MessageId, pub attachments: Vec<Attachment>, pub author: User, pub channel_id: ChannelId, pub content: String, pub edited_timestamp: Option<String>, pub embeds: Vec<Embed>, pub hit: bool, pub kind: MessageType, pub mention_everyone: bool, pub mention_roles: Vec<RoleId>, pub mentions: Vec<User>, pub nonce: Option<String>, pub pinned: bool, pub reactions: Vec<MessageReaction>, pub timestamp: String, pub tts: bool, pub webhook_id: Option<WebhookId>, }
A representation of a message sent over a guild's text channel, a group, or a private channel.
Fields
id: MessageId
Message Id. Can be used to calculate the message creation date.
attachments: Vec<Attachment>
Array of attached files a message has.
User that sent the message.
channel_id: ChannelId
Channel to which the message was sent.
content: String
Message's content.
edited_timestamp: Option<String>
If the message was edited, this will show the last edit timestamp.
embeds: Vec<Embed>
Array of embeds a message has.
hit: bool
Whether the message is the "found" message in a search. Note that this is only relevant in the context of searches, and will otherwise always be false
.
kind: MessageType
Lets you differentiate system messages and regular messages.
mention_everyone: bool
Shows you whether this message actually mentions everyone or not.
mention_roles: Vec<RoleId>
Array of roles mentioned by the message.
mentions: Vec<User>
Array of users mentioned by the messages.
nonce: Option<String>
Non-repeating number used for ensuring message order.
pinned: bool
True if message is pinned.
reactions: Vec<MessageReaction>
Array of reactions performed on the message.
timestamp: String
Initial message creation timestamp calculated from Id.
tts: bool
True if message was sent with /tts command.
webhook_id: Option<WebhookId>
An id of a webhook if message was sent using one.
Methods
impl Message
[src]
fn ack<M: Into<MessageId>>(&self) -> Result<()>
Marks the Channel
as being read up to the message.
Refer to the documentation for rest::ack_message
for more
information.
Errors
If the cache
is enabled, returns a
ClientError::InvalidOperationAsBot
if the current user is a bot
user.
fn delete(&self) -> 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
ClientError::InvalidPermissions
if the current user does not have
the required permissions.
fn delete_reactions(&self) -> 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
ClientError::InvalidPermissions
if the current user does not have
the required permissions.
fn edit<F>(&mut self, new_content: &str, embed: F) -> Result<()> where F: FnOnce(CreateEmbed) -> CreateEmbed
Edits this message, replacing the original content with new content.
If editing a message and not using an embed, just return the embed builder directly, via:
message.edit("new content", |f| f);
Note: You must be the author of the message to be able to do this.
Note: Messages must be at most 2000 unicode code points.
Errors
If the cache
is enabled, returns a ClientError::InvalidUser
if the
current user is not the author.
Returns a ClientError::MessageTooLong
if the content of the message
is over the above limit, containing the number of unicode code points
over the limit.
fn content_safe(&self) -> String
Returns message content, but with user and role mentions replaced with names and everyone/here mentions cancelled.
fn get_reaction_users<R, U>(&self,
reaction_type: R,
limit: Option<u8>,
after: Option<U>)
-> Result<Vec<User>> where R: Into<ReactionType>, U: Into<UserId>
reaction_type: R,
limit: Option<u8>,
after: Option<U>)
-> Result<Vec<User>> where R: Into<ReactionType>, U: Into<UserId>
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.
fn guild_id(&self) -> Option<GuildId>
Retrieves the Id of the guild that the message was sent in, if sent in one.
Returns None
if the channel data or guild data does not exist in the
cache.
fn is_private(&self) -> bool
True if message was sent using direct messages.
fn overflow_length(content: &str) -> Option<u64>
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.
fn pin(&self) -> Result<()>
Pins this message to its channel.
Note: Requires the Manage Messages permission.
Errors
If the cache
is enabled, returns a
ClientError::InvalidPermissions
if the current user does not have
the required permissions.
fn react<R: Into<ReactionType>>(&self, reaction_type: R) -> Result<()>
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
ClientError::InvalidPermissions
if the current user does not have
the required permissions.
fn reply(&self, content: &str) -> 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
ClientError::InvalidPermissions
if the current user does not have
the required permissions.
Returns a ClientError::MessageTooLong
if the content of the message
is over the above limit, containing the number of unicode code points
over the limit.
fn unpin(&self) -> Result<()>
Unpins the message from its channel.
Note: Requires the Manage Messages permission.
Errors
If the cache
is enabled, returns a
ClientError::InvalidPermissions
if the current user does not have
the required permissions.
Trait Implementations
impl Clone for Message
[src]
fn clone(&self) -> Message
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more