Represents a file to upload to Discord.
Use the builder functions to create file structs:
# From binary data
EDA.File.from_binary(png_data, "image.png")
EDA.File.from_binary(png_data, "image.png", description: "Alt text", spoiler: true)
# From a file path
EDA.File.from_path("/path/to/image.png")
EDA.File.from_path("/path/to/image.png", name: "custom.png", description: "Alt text")Then pass files to message functions:
EDA.API.Message.create(channel_id, content: "Check this!", files: [file])
Summary
Functions
Returns the filename Discord should show.
Creates a file from binary data.
Creates a file from a filesystem path.
Types
Functions
Returns the filename Discord should show.
This is the name as given. Spoilering used to be requested by prefixing the filename with
SPOILER_, which meant the prefix was visible in the name forever after; EDA now sets the
is_spoiler field of the attachment request instead, so :spoiler no longer rewrites the
name. EDA.Attachment.spoiler?/1 reads the resulting flag back.
A name you prefix yourself still works — Discord honours the convention — and is left alone.
Creates a file from binary data.
Accepts both Elixir binaries (<<...>>) and byte lists ([0, 1, 2, ...]).
Lists are automatically converted — this is useful when receiving data from
Rust NIFs that return Vec<u8> (Rustler converts these to Erlang lists).
Options
:description- Alt text for the file (max 1024 chars):spoiler- Iftrue, Discord blurs the file until clicked
Creates a file from a filesystem path.
Reads the file and extracts the filename from the path.
Options
:name- Override the filename (defaults to basename of path):description- Alt text for the file (max 1024 chars):spoiler- Iftrue, Discord blurs the file until clicked