Skip to content

Conversation

@lynn2910
Copy link

Closes #2133

This PR has for purpose to address #2133, by adding documentation on how to send attachment file, other than URLs.

@github-actions github-actions bot added c-book Affects the book c-util Affects the util crate labels Sep 28, 2025
Copy link
Member

@Erk- Erk- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The notes I added to the book version should of course also be reflected in the mod file. After looking again I can see that it is only the book version that has these problems.

It should probably be marked to not run in the mod.rs file as a good example probably loaded the image from disk and we don't want to make the test read from the disk. We still want to make sure it builds though.


let message = client
.create_message(channel_id)
.attachments(&[("bestpony.png".as_bytes(), "bestpony.png".to_owned(), 0)])?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is a bit wrong, you can no longer have the 3-tuple to make a attachment, instead you should use the Attachment struct.

So it should use Attachment::from_bytes(filename: String, file: Vec<[u8]>, id: u64) instead. The first field in the tuple (or file in Attachment::from_bytes) should be the actual image data.

Comment on lines +105 to +106
.attachments(&[("bestpony.png".as_bytes(), "bestpony.png".to_owned(), 0)])?
.embeds(&[embed.build()])?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attachments and embeds no longer return a result it it instead moved to the end.

Copy link
Member

@Erk- Erk- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes needed to bring the rustdoc version up to scratch

/// .validate()?
/// .build();
///
/// // Then, send both the embed and the attachment with your message
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some statements are missing below here.

///
/// Set the image source to a file attachment:
///
/// ```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// ```
/// ```no_run

@vilgotf
Copy link
Member

vilgotf commented Nov 8, 2025

Please retarget this to main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c-book Affects the book c-util Affects the util crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants