Struct serenity::model::channel::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<DateTime<FixedOffset>>,
    pub embeds: Vec<Embed>,
    pub kind: MessageType,
    pub mention_everyone: bool,
    pub mention_roles: Vec<RoleId>,
    pub mentions: Vec<User>,
    pub nonce: Value,
    pub pinned: bool,
    pub reactions: Vec<MessageReaction>,
    pub timestamp: DateTime<FixedOffset>,
    pub tts: bool,
    pub webhook_id: Option<WebhookId>,
}

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

Fields

The unique Id of the message. Can be used to calculate the creation date of the message.

An vector of the files attached to a message.

The user that sent the message.

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

The content of the message.

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

Array of embeds sent with the message.

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

Indicator of whether the message mentions everyone.

Array of Roles' Ids mentioned in the message.

Array of users mentioned in the message.

Non-repeating number used for ensuring message order.

Indicator of whether the message is pinned.

Array of reactions performed on the message.

Initial message creation timestamp, calculated from its Id.

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.

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

Methods

impl Message
[src]

[src]

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"),
    };
});

[src]

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

[src]

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.

[src]

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.

[src]

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:

Be careful when using this code, it's not being tested!
// 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.

[src]

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

[src]

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.

[src]

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.

[src]

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.

[src]

True if message was sent using direct messages.

[src]

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.

[src]

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.

[src]

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.

[src]

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.

[src]

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.

[src]

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 Clone for Message
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Message
[src]

[src]

Formats the value using the given formatter.