pub struct GetMessages { /* private fields */ }
Expand description
Builds a request to the API to retrieve messages.
This accepts 2 types of parameters. The first type filters messages based on Id, and is set by one of the following:
These are mutually exclusive, and override each other if called sequentially. If one is not specified, messages are simply sorted by most recent.
The other parameter specifies the number of messages to retrieve. This is optional, and defaults to 50 if not specified.
See GuildChannel::messages
for more examples.
§Examples
Creating a GetMessages
builder to retrieve the first 25 messages after the message with an
Id of 158339864557912064
:
use serenity::builder::GetMessages;
use serenity::model::id::{ChannelId, MessageId};
// you can then pass it into a function which retrieves messages:
let channel_id = ChannelId::new(81384788765712384);
let builder = GetMessages::new().after(MessageId::new(158339864557912064)).limit(25);
let _messages = channel_id.messages(&http, builder).await?;
Implementations§
Source§impl GetMessages
impl GetMessages
Sourcepub fn new() -> Self
pub fn new() -> Self
Equivalent to Self::default
.
Sourcepub fn after(self, message_id: impl Into<MessageId>) -> Self
pub fn after(self, message_id: impl Into<MessageId>) -> Self
Indicates to retrieve the messages after a specific message, given its Id.
Sourcepub fn around(self, message_id: impl Into<MessageId>) -> Self
pub fn around(self, message_id: impl Into<MessageId>) -> Self
Indicates to retrieve the messages around a specific message, in other words in either direction from the message in time.
Trait Implementations§
Source§impl Builder for GetMessages
impl Builder for GetMessages
Source§fn execute<'life0, 'async_trait>(
self,
cache_http: impl 'async_trait + CacheHttp,
ctx: Self::Context<'life0>,
) -> Pin<Box<dyn Future<Output = Result<Self::Built>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
self,
cache_http: impl 'async_trait + CacheHttp,
ctx: Self::Context<'life0>,
) -> Pin<Box<dyn Future<Output = Result<Self::Built>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Gets messages from the channel.
Note: If the user does not have the Read Message History permission, returns an empty
Vec
.
§Errors
Returns Error::Http
if the current user lacks permission.
Source§type Context<'ctx> = ChannelId
type Context<'ctx> = ChannelId
type Built = Vec<Message>
Source§impl Clone for GetMessages
impl Clone for GetMessages
Source§fn clone(&self) -> GetMessages
fn clone(&self) -> GetMessages
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more