Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed Footer, Thumbnail & Image can be local files, not only HTTP(S) #2776

Closed
keiveulbugs opened this issue Feb 25, 2024 · 3 comments
Closed

Comments

@keiveulbugs
Copy link

keiveulbugs commented Feb 25, 2024

In the documentation it states that the Footer, Thumbnail & Image only support HTTP(S).

https://docs.rs/serenity/latest/serenity/builder/struct.CreateEmbed.html#method.image
https://docs.rs/serenity/latest/serenity/builder/struct.CreateEmbed.html#method.thumbnail
https://docs.rs/serenity/latest/serenity/builder/struct.CreateEmbedFooter.html#method.icon_url

This is a bit misleading as you can use local files when attached to the message. I tried fixing the docs, but have not a setup ready at the moment to test if the docs are working and if it works in pure Serenity. (In poise it works, but uses the CreateReply function.)

Would love if someone could check this and add something to the docs about how to use local files.

use serenity::builder::{CreateEmbed, CreateAttachment, CreateEmbedFooter};
// First we create an attachment
let attachment = CreateAttachment::path("images/loss.jpg").await.expect("Could not find image");

// Then we create an embed where we add the image/footer/thumbnail
let embed = CreateEmbed::default()
     .image("attachment://loss.jpg")
     .thumbnail("attachment://loss.jpg")
     .footer(
            CreateEmbedFooter::new("Loss footer")
                .icon_url("attachment://loss.jpg"),
     );

// I think this should work in Serenity:
 let builder = CreateMessage::new().embed(embed).add_file(attachment);

// In Poise we do the following and that works for sure:
 ctx.send(CreateReply::default().embed(embed).attachment(attachment))
       .await?;
@floris-xlx
Copy link

You can create an attachment an attach it as such

let img_path: &Path = Path::new("./img.png");
let attachment_bytes: Vec<u8> = std::fs::read(img_path).expect("Failed to read card file");
let attachment: CreateAttachment = CreateAttachment::bytes(
    attachment_bytes,
    "img.png"
);
// attachment can be routed thru an embed aswell

CreateMessage::default()
    .add_file(attachment)
    .content("@everyone")

@ivinjabraham
Copy link
Contributor

This seems correct, not sure why the docs say it only supports HTTPS for those methods. CreateEmbed::attachment even specifies CreateEmbed::image works with local attachments by using the attachment:// syntax. So do the Discord docs.

@ivinjabraham
Copy link
Contributor

Fixed in #2959

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants