Function schedule_message_deletion

Source
pub async fn schedule_message_deletion(
    sent_message: ReplyHandle<'_>,
    ctx: ApplicationContext<'_, Data, Box<dyn Error + Send + Sync>>,
) -> Result<(), Box<dyn Error + Send + Sync>>
Expand description

⚙️ Function: Schedules the deletion of a Discord message after a delay.

This function delays the deletion of a Discord message by 60 seconds. After the delay, the function attempts to delete the message from the channel. It ensures that messages sent by the bot (e.g., error messages or status updates) are automatically removed after a certain time to keep the chat clean.

§Parameters:

  • sent_message: A ReplyHandle representing the message to be deleted. This handle provides access to the message object, allowing the function to delete it once the delay has passed.
  • ctx: The application context, which provides access to Discord methods (such as message deletion) and other necessary data like API keys.

§Returns:

  • Result<(), Error>: If successful, returns Ok(()). If an error occurs while fetching the message or deleting it, returns an Error.

§⚠️ Notes:

  • The function uses tokio::time::sleep to pause execution for 60 seconds before attempting to delete the message.
  • If the message cannot be fetched (e.g., due to permissions or being deleted manually), the deletion attempt will silently fail.
  • This function is typically used in scenarios where temporary messages (like errors or status updates) need to be cleaned up automatically after a short period.

§Example:

schedule_message_deletion(sent_message, ctx).await?;

After 60 seconds, the message will be deleted from the Discord channel.