pub trait MessageExt: Message {
Show 14 methods
// Provided methods
fn reply<B: Backend>(
&self,
ctx: &Context<B>,
body: impl Into<CreateMessage>,
) -> impl Future<Output = Result<Arc<CachedMessage>, Error>> + Send { ... }
fn edit<B: Backend>(
&self,
ctx: &Context<B>,
body: &EditMessage,
) -> impl Future<Output = Result<Arc<CachedMessage>, Error>> + Send { ... }
fn delete<B: Backend>(
&self,
ctx: &Context<B>,
) -> impl Future<Output = Result<(), Error>> + Send { ... }
fn react<'e, B: Backend>(
&self,
ctx: &Context<B>,
emoji: impl Into<ReactionEmoji<'e>>,
) -> impl Future<Output = Result<(), Error>> + Send { ... }
fn pin<B: Backend>(
&self,
ctx: &Context<B>,
reason: Option<&str>,
) -> impl Future<Output = Result<(), Error>> + Send { ... }
fn unpin<B: Backend>(
&self,
ctx: &Context<B>,
reason: Option<&str>,
) -> impl Future<Output = Result<(), Error>> + Send { ... }
fn start_thread<B: Backend>(
&self,
ctx: &Context<B>,
body: &StartThreadFromMessage,
reason: Option<&str>,
) -> impl Future<Output = Result<Arc<Channel>, Error>> + Send { ... }
fn crosspost<B: Backend>(
&self,
ctx: &Context<B>,
) -> impl Future<Output = Result<Arc<CachedMessage>, Error>> + Send { ... }
fn remove_reaction<'e, B: Backend>(
&self,
ctx: &Context<B>,
emoji: impl Into<ReactionEmoji<'e>>,
user: Option<UserId>,
) -> impl Future<Output = Result<(), Error>> + Send { ... }
fn remove_all_reactions<B: Backend>(
&self,
ctx: &Context<B>,
) -> impl Future<Output = Result<(), Error>> + Send { ... }
fn reaction_collector<B: Backend>(
&self,
ctx: &Context<B>,
) -> CollectorBuilder<ReactionEvent> { ... }
fn await_reactions<B: Backend>(
&self,
ctx: &Context<B>,
) -> CollectorBuilder<ReactionEvent, All> { ... }
fn component_collector<B: Backend>(
&self,
ctx: &Context<B>,
) -> CollectorBuilder<ComponentInteraction> { ... }
fn await_component<B: Backend>(
&self,
ctx: &Context<B>,
) -> CollectorBuilder<ComponentInteraction, First> { ... }
}Expand description
Actions on a message: Message or CachedMessage.
This trait is sealed.
discord.js counterpart: the methods of Message.
§Examples
client.on(Events::MessageCreate, |ctx, msg| async move {
if msg.content == "!ping" {
let reply = msg.reply(&ctx, "Pong!").await?;
reply.react(&ctx, "🏓").await?;
}
Ok(())
});Provided Methods§
Sourcefn reply<B: Backend>(
&self,
ctx: &Context<B>,
body: impl Into<CreateMessage>,
) -> impl Future<Output = Result<Arc<CachedMessage>, Error>> + Send
fn reply<B: Backend>( &self, ctx: &Context<B>, body: impl Into<CreateMessage>, ) -> impl Future<Output = Result<Arc<CachedMessage>, Error>> + Send
Replies to this message in the same channel: the reply references this message
(Discord shows it as a reply). Accepts anything that converts into a
CreateMessage, such as &str or String. The reply is cached.
discord.js counterpart: Message#reply.
§Errors
Returns the REST error if the message could not be sent (see
Rest::create_message).
Sourcefn edit<B: Backend>(
&self,
ctx: &Context<B>,
body: &EditMessage,
) -> impl Future<Output = Result<Arc<CachedMessage>, Error>> + Send
fn edit<B: Backend>( &self, ctx: &Context<B>, body: &EditMessage, ) -> impl Future<Output = Result<Arc<CachedMessage>, Error>> + Send
Edits this message (MessageManager::edit).
discord.js counterpart: Message#edit.
§Errors
Returns the REST error if the request failed.
Sourcefn delete<B: Backend>(
&self,
ctx: &Context<B>,
) -> impl Future<Output = Result<(), Error>> + Send
fn delete<B: Backend>( &self, ctx: &Context<B>, ) -> impl Future<Output = Result<(), Error>> + Send
Deletes this message (MessageManager::delete).
discord.js counterpart: Message#delete.
§Errors
Returns the REST error if the request failed.
Sourcefn react<'e, B: Backend>(
&self,
ctx: &Context<B>,
emoji: impl Into<ReactionEmoji<'e>>,
) -> impl Future<Output = Result<(), Error>> + Send
fn react<'e, B: Backend>( &self, ctx: &Context<B>, emoji: impl Into<ReactionEmoji<'e>>, ) -> impl Future<Output = Result<(), Error>> + Send
Reacts to this message (MessageManager::react): a &str for a Unicode emoji, or a
custom ReactionEmoji.
discord.js counterpart: Message#react.
§Errors
Returns the REST error if the request failed.
Sourcefn pin<B: Backend>(
&self,
ctx: &Context<B>,
reason: Option<&str>,
) -> impl Future<Output = Result<(), Error>> + Send
fn pin<B: Backend>( &self, ctx: &Context<B>, reason: Option<&str>, ) -> impl Future<Output = Result<(), Error>> + Send
Pins this message (MessageManager::pin).
discord.js counterpart: Message#pin.
§Errors
Returns the REST error if the request failed.
Sourcefn unpin<B: Backend>(
&self,
ctx: &Context<B>,
reason: Option<&str>,
) -> impl Future<Output = Result<(), Error>> + Send
fn unpin<B: Backend>( &self, ctx: &Context<B>, reason: Option<&str>, ) -> impl Future<Output = Result<(), Error>> + Send
Unpins this message (MessageManager::unpin).
discord.js counterpart: Message#unpin.
§Errors
Returns the REST error if the request failed.
Sourcefn start_thread<B: Backend>(
&self,
ctx: &Context<B>,
body: &StartThreadFromMessage,
reason: Option<&str>,
) -> impl Future<Output = Result<Arc<Channel>, Error>> + Send
fn start_thread<B: Backend>( &self, ctx: &Context<B>, body: &StartThreadFromMessage, reason: Option<&str>, ) -> impl Future<Output = Result<Arc<Channel>, Error>> + Send
Starts a thread from this message (MessageManager::start_thread).
discord.js counterpart: Message#startThread.
§Errors
Returns the REST error if the request failed.
Sourcefn crosspost<B: Backend>(
&self,
ctx: &Context<B>,
) -> impl Future<Output = Result<Arc<CachedMessage>, Error>> + Send
fn crosspost<B: Backend>( &self, ctx: &Context<B>, ) -> impl Future<Output = Result<Arc<CachedMessage>, Error>> + Send
Publishes this announcement-channel message to the following channels
(MessageManager::crosspost).
discord.js counterpart: Message#crosspost.
§Errors
Returns the REST error if the request failed.
Sourcefn remove_reaction<'e, B: Backend>(
&self,
ctx: &Context<B>,
emoji: impl Into<ReactionEmoji<'e>>,
user: Option<UserId>,
) -> impl Future<Output = Result<(), Error>> + Send
fn remove_reaction<'e, B: Backend>( &self, ctx: &Context<B>, emoji: impl Into<ReactionEmoji<'e>>, user: Option<UserId>, ) -> impl Future<Output = Result<(), Error>> + Send
Removes a reaction from this message: the bot’s own with user: None, or another
user’s (MessageManager::remove_reaction).
discord.js counterpart: ReactionUserManager#remove.
§Errors
Returns the REST error if the request failed.
Sourcefn remove_all_reactions<B: Backend>(
&self,
ctx: &Context<B>,
) -> impl Future<Output = Result<(), Error>> + Send
fn remove_all_reactions<B: Backend>( &self, ctx: &Context<B>, ) -> impl Future<Output = Result<(), Error>> + Send
Removes every reaction from this message (MessageManager::remove_all_reactions).
discord.js counterpart: ReactionManager#removeAll.
§Errors
Returns the REST error if the request failed.
Sourcefn reaction_collector<B: Backend>(
&self,
ctx: &Context<B>,
) -> CollectorBuilder<ReactionEvent>
fn reaction_collector<B: Backend>( &self, ctx: &Context<B>, ) -> CollectorBuilder<ReactionEvent>
A collector of the reactions added to this message (D-263, D-269); with
dispose it also yields their removals.
It ends at its limits, or when the message, its channel, thread or guild is deleted.
Needs the GUILD_MESSAGE_REACTIONS or DIRECT_MESSAGE_REACTIONS intent.
discord.js counterpart: Message#createReactionCollector.
§Examples
let mut votes = poll
.reaction_collector(&ctx)
.time(Duration::from_secs(60))
.build();
while let Some(ReactionEvent::Added(vote)) = votes.next().await {
println!("{} voted {:?}", vote.user_id, vote.emoji.name());
}Sourcefn await_reactions<B: Backend>(
&self,
ctx: &Context<B>,
) -> CollectorBuilder<ReactionEvent, All>
fn await_reactions<B: Backend>( &self, ctx: &Context<B>, ) -> CollectorBuilder<ReactionEvent, All>
Collects the reactions added to this message until the collector ends, gathered by
emoji (reaction_key); set a limit (time, max,
…), or it only ends with the message.
discord.js counterpart: Message#awaitReactions.
§Examples
let votes = poll.await_reactions(&ctx).time(Duration::from_secs(60)).await;
let yes = votes.get("👍").map_or(0, |reaction| reaction.count());
println!("{yes} yes votes ({})", votes.reason());Sourcefn component_collector<B: Backend>(
&self,
ctx: &Context<B>,
) -> CollectorBuilder<ComponentInteraction>
fn component_collector<B: Backend>( &self, ctx: &Context<B>, ) -> CollectorBuilder<ComponentInteraction>
A collector of the component interactions (buttons, select menus) on this message.
It ends at its limits, or when the message, its channel, thread or guild is deleted.
discord.js counterpart: Message#createMessageComponentCollector.
§Examples
let mut clicks = menu
.component_collector(&ctx)
.idle(Duration::from_secs(120))
.build();
while let Some(click) = clicks.next().await {
click.reply(&ctx, format!("You pressed {}", click.custom_id)).await?;
}Sourcefn await_component<B: Backend>(
&self,
ctx: &Context<B>,
) -> CollectorBuilder<ComponentInteraction, First>
fn await_component<B: Backend>( &self, ctx: &Context<B>, ) -> CollectorBuilder<ComponentInteraction, First>
Waits for one component interaction on this message (D-268); set a
time, or it only ends with the message.
discord.js counterpart: Message#awaitMessageComponent.
§Errors
CollectorError with the reason if the collector
ended first (EndReason::Time, …).
§Examples
match prompt.await_component(&ctx).time(Duration::from_secs(30)).await {
Ok(click) if click.custom_id == "confirm" => click.update(&ctx, "Confirmed").await?,
Ok(click) => click.update(&ctx, "Cancelled").await?,
Err(_) => println!("no answer in 30 seconds"),
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".