EDA.File (EDA v0.3.0)

Copy Markdown View Source

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 effective filename, with SPOILER_ prefix if spoiler is true.

Creates a file from binary data.

Creates a file from a filesystem path.

Types

t()

@type t() :: %EDA.File{
  data: binary(),
  description: String.t() | nil,
  name: String.t(),
  spoiler: boolean()
}

Functions

effective_name(file)

@spec effective_name(t()) :: String.t()

Returns the effective filename, with SPOILER_ prefix if spoiler is true.

from_binary(data, name, opts \\ [])

@spec from_binary(binary() | list(), String.t(), keyword()) :: t()

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 - If true, prefixes the filename with SPOILER_

from_path(path, opts \\ [])

@spec from_path(
  String.t(),
  keyword()
) :: t()

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 - If true, prefixes the filename with SPOILER_