Skip to content

Commit

Permalink
Remove doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrasnitski committed Nov 25, 2024
1 parent fa24015 commit 442e25b
Showing 1 changed file with 14 additions and 30 deletions.
44 changes: 14 additions & 30 deletions src/builder/edit_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,38 +107,22 @@ impl<'a> EditMessage<'a> {
/// Suppress or unsuppress embeds in the message, this includes those generated by Discord
/// themselves.
///
/// If this is sent directly after posting the message, there is a small chance Discord hasn't
/// yet fully parsed the contained links and generated the embeds, so this embed suppression
/// request has no effect. To mitigate this, you can defer the embed suppression until the
/// embeds have loaded:
///
/// ```rust,no_run
/// # use serenity::all::*;
/// # #[cfg(feature = "collector")]
/// # async fn test(ctx: &Context, channel_id: ChannelId) -> Result<(), Error> {
/// use std::time::Duration;
///
/// use futures::StreamExt;
///
/// let mut msg = channel_id.say(&ctx.http, "<link that spawns an embed>").await?;
///
/// // When the embed appears, a MessageUpdate event is sent and we suppress the embed.
/// // No MessageUpdate event is sent if the message contains no embeddable link or if the link
/// // has been posted before and is still cached in Discord's servers (in which case the
/// // embed appears immediately), no MessageUpdate event is sent. To not wait forever in those
/// // cases, a timeout of 2000ms was added.
/// let msg_id = msg.id;
/// let mut message_updates = serenity::collector::collect(&ctx.shard, move |ev| match ev {
/// Event::MessageUpdate(x) if x.id == msg_id => Some(()),
/// _ => None,
/// });
/// let _ = tokio::time::timeout(Duration::from_millis(2000), message_updates.next()).await;
/// msg.edit(&ctx, EditMessage::new().suppress_embeds(true)).await?;
/// # Ok(()) }
/// ```
/// If this is sent directly after the message has been posted, there is a small chance Discord
/// hasn't yet fully parsed the contained links and generated the embeds, so this embed
/// suppression request has no effect. Note that this is less likely for messages you have not
/// created yourself. There are two ways to mitigate this:
/// 1. If you are editing a message you created, simply set the
/// [`MessageFlags::SUPPRESS_EMBEDS`] flag on creation using [`CreateMessage::flags`] to
/// avoid having to edit the message in the first place.
/// 2. Defer the embed suppression until the embed has loaded. When the embed appears, a
/// `MessageUpdate` event is sent over the gateway. Note that this will not occur if a link
/// has been previously posted and is still cached by Discord, in which case the embed will
/// immediately appear.
///
/// [`CreateMessage::flags`]: super::CreateMessage::flags
pub fn suppress_embeds(mut self, suppress: bool) -> Self {
// At time of writing, only `SUPPRESS_EMBEDS` can be set/unset when editing messages. See
// for details: https://discord.com/developers/docs/resources/channel#edit-message-jsonform-params
// for details: https://discord.com/developers/docs/resources/message#edit-message-jsonform-params
let flags =
suppress.then_some(MessageFlags::SUPPRESS_EMBEDS).unwrap_or_else(MessageFlags::empty);

Expand Down

0 comments on commit 442e25b

Please sign in to comment.