'How to reply with an image with discord bot

I'm new to rust and as a practice project I'm building a bot using Serenity to handle the interactions with Discord. The bot should be able to reply to a message with an image. I can get the bot to post the image on the channel using CreateMessage like this:

let f = [(&tokio::fs::File::open("image.png").await?, "image.png")];
return match msg.channel_id.send_message(&context.http, |m| {
    m.content(replied_message.author);
    m.files(f);
    return m;
}).await {
    Ok(_) => Ok(()),
    Err(why) => Err(CommandError::from(why)),
};

Unfortunately this method doesn't work with reply, which wants a content that implements std::fmt::Display. I could use MessageBuilder, but it constructs a string and I don't know how to add the image to that, unless I add an URL. The image is an image::DynamicImage instance and serving it from another service is unpractical to say the least.

How can I use message.reply_ping(&context.http, &reply) to send an image?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source