[−][src]Struct serenity::model::channel::Message
A representation of a message over a guild's text channel, a group, or a private channel.
Fields
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.
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<DateTime<FixedOffset>>
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 Role
s' Ids mentioned in the message.
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: DateTime<FixedOffset>
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.
Methods
impl Message
[src]
impl Message
pub fn channel(&self) -> Option<Channel>
[src]
pub fn channel(&self) -> Option<Channel>
Retrieves the related channel located in the cache.
Returns None
if the channel is not in the cache.
Examples
On command, print the name of the channel that a message took place in:
use serenity::model::channel::Channel; use serenity::framework::StandardFramework; client.with_framework(StandardFramework::new() .configure(|c| c.prefix("~")) .cmd("channelname", channel_name)); command!(channel_name(_ctx, msg) { let _ = match msg.channel() { Some(Channel::Category(c)) => msg.reply(&c.read().name), Some(Channel::Group(c)) => msg.reply(&c.read().name()), Some(Channel::Guild(c)) => msg.reply(&c.read().name), Some(Channel::Private(c)) => { let channel = c.read(); let user = channel.recipient.read(); msg.reply(&format!("DM with {}", user.name.clone())) }, None => msg.reply("Unknown"), }; });
pub fn is_own(&self) -> bool
[src]
pub fn is_own(&self) -> bool
A util function for determining whether this message was sent by someone else, or the bot.
pub fn delete(&self) -> Result<()>
[src]
pub 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
ModelError::InvalidPermissions
if the current user does not have
the required permissions.
pub fn delete_reactions(&self) -> Result<()>
[src]
pub 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
ModelError::InvalidPermissions
if the current user does not have
the required permissions.
pub fn edit<F>(&mut self, f: F) -> Result<()> where
F: FnOnce(EditMessage) -> EditMessage,
[src]
pub fn edit<F>(&mut self, f: F) -> Result<()> where
F: FnOnce(EditMessage) -> EditMessage,
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(|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.
pub fn content_safe(&self) -> String
[src]
pub fn content_safe(&self) -> String
Returns message content, but with user and role mentions replaced with names and everyone/here mentions cancelled.
pub fn reaction_users<R, U>(
&self,
reaction_type: R,
limit: Option<u8>,
after: U
) -> Result<Vec<User>> where
R: Into<ReactionType>,
U: Into<Option<UserId>>,
[src]
pub fn reaction_users<R, U>(
&self,
reaction_type: R,
limit: Option<u8>,
after: U
) -> Result<Vec<User>> where
R: Into<ReactionType>,
U: Into<Option<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.
pub fn guild(&self) -> Option<Arc<RwLock<Guild>>>
[src]
pub fn guild(&self) -> Option<Arc<RwLock<Guild>>>
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 guild_id
or
if the Guild itself is not cached.
Requires the cache
feature be enabled.
pub fn guild_id(&self) -> Option<GuildId>
[src]
pub fn guild_id(&self) -> Option<GuildId>
: Use guild_id
structfield instead
Retrieves the Id of the guild that the message was sent in, if sent in one.
Refer to guild_id
for more information.
pub fn is_private(&self) -> bool
[src]
pub fn is_private(&self) -> bool
True if message was sent using direct messages.
pub fn member(&self) -> Option<Member>
[src]
pub fn member(&self) -> Option<Member>
Retrieves a clone of the author's Member instance, if this message was sent in a guild.
Note that since this clones, it is preferable performance-wise to
manually retrieve the guild from the cache and access
Guild::members
.
pub fn overflow_length(content: &str) -> Option<u64>
[src]
pub 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.
pub fn pin(&self) -> Result<()>
[src]
pub fn pin(&self) -> 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.
pub fn react<R: Into<ReactionType>>(&self, reaction_type: R) -> Result<()>
[src]
pub 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
ModelError::InvalidPermissions
if the current user does not have the
required permissions.
pub fn reply(&self, content: &str) -> Result<Message>
[src]
pub 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
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.
pub fn mentions_user_id<I: Into<UserId>>(&self, id: I) -> bool
[src]
pub fn mentions_user_id<I: Into<UserId>>(&self, id: I) -> bool
Checks whether the message mentions passed UserId
.
pub fn mentions_user(&self, user: &User) -> bool
[src]
pub fn mentions_user(&self, user: &User) -> bool
Checks whether the message mentions passed User
.
pub fn unpin(&self) -> Result<()>
[src]
pub fn unpin(&self) -> 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.
Trait Implementations
impl From<Message> for MessageId
[src]
impl From<Message> for MessageId
impl<'a> From<&'a Message> for MessageId
[src]
impl<'a> From<&'a Message> for MessageId
impl AsRef<MessageId> for Message
[src]
impl AsRef<MessageId> for Message
impl Clone for Message
[src]
impl Clone for Message
fn clone(&self) -> Message
[src]
fn clone(&self) -> Message
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Debug for Message
[src]
impl Debug for Message
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Serialize for Message
[src]
impl Serialize for Message
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<'de> Deserialize<'de> for Message
[src]
impl<'de> Deserialize<'de> for Message
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
type Owned = T
fn to_owned(&self) -> T
[src]
fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)
[src]
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
impl<T> Erased for T
impl<T> Erased for T
impl<T> Typeable for T where
T: Any,
impl<T> Typeable for T where
T: Any,
impl<T> DebugAny for T where
T: Any + Debug,
[src]
impl<T> DebugAny for T where
T: Any + Debug,
impl<T> CloneAny for T where
T: Clone + Any,
[src]
impl<T> CloneAny for T where
T: Clone + Any,
fn clone_any(&self) -> Box<dyn CloneAny + 'static>
[src]
fn clone_any(&self) -> Box<dyn CloneAny + 'static>
fn clone_any_send(&self) -> Box<dyn CloneAny + 'static + Send> where
T: Send,
[src]
fn clone_any_send(&self) -> Box<dyn CloneAny + 'static + Send> where
T: Send,
fn clone_any_sync(&self) -> Box<dyn CloneAny + 'static + Sync> where
T: Sync,
[src]
fn clone_any_sync(&self) -> Box<dyn CloneAny + 'static + Sync> where
T: Sync,
fn clone_any_send_sync(&self) -> Box<dyn CloneAny + 'static + Sync + Send> where
T: Send + Sync,
[src]
fn clone_any_send_sync(&self) -> Box<dyn CloneAny + 'static + Sync + Send> where
T: Send + Sync,
impl<T> UnsafeAny for T where
T: Any,
impl<T> UnsafeAny for T where
T: Any,