Alchemy.Embed (alchemy v0.7.0)
A module containing structs and functions relative to Embeds.
Embeds allow you to format messages in a structured, and quite pretty way; much more than can be done with simple text. For a basic idea of how embeds work, check this link.
Example Usage
Cogs.def embed do
%Embed{}
|> title("The BEST embed")
|> description("the best description")
|> image("http://i.imgur.com/4AiXzf8.jpg")
|> Embed.send
endNote that this is equivalent to:
Cogs.def embed do
%Embed{title: "The BEST embed",
description: "the best description",
image: "http://i.imgur.com/4AiXzf8.jpg"}
|> Embed.send
endFile Attachments
The fields that take urls can also take a special "attachment" url referencing files uploaded alongside the embed.
Cogs.def foo do
%Embed{}
|> image("attachment://foo.png")
|> Embed.send("", file: "foo.png")
end
Link to this section Summary
Types
Represents a file attached to an embed.
Represents the author of an embed.
Represents a field in an embed.
Represents an Embed footer.
Represents the image of an embed.
Represents the provider of an embed.
Represents the thumnail of an embed.
Represents a video attached to an embed.
Functions
Adds author information to an embed.
Sets the color of an embed
Adds a description to an embed.
Adds a field to an embed.
Adds a footer to an embed.
Sets the main image of the embed.
Sends an embed to the same channel as the message triggering a command.
Adds a thumbnail to an embed.
Adds a timestamp to an embed.
Adds a title to an embed.
Sets the url for an embed.
Link to this section Types
attachment()
Specs
attachment() :: %Alchemy.Attachment{
filename: String.t(),
height: Integer | nil,
id: String.t(),
proxy_url: url(),
size: Integer,
url: url(),
width: Integer | nil
}
Represents a file attached to an embed.
idThe attachment id
filenameThe name of the file attached
sizeThe size of the file attached
urlThe source url of a file
proxy_urlA proxied url of a file
heightThe height of the file, if it's an image
widthThe width of a file, if it's an image
author()
Specs
author() :: %Alchemy.Embed.Author{
icon_url: url(),
name: String.t(),
proxy_icon_url: url(),
url: url()
}
Represents the author of an embed.
nameThe name of the author
urlThe author's url
icon_urlA link to the author's icon image
proxy_icon_urlA proxied url for the author's icon image
field()
Specs
Represents a field in an embed.
nameThe title of the field
valueThe text of the field
inlineWhether or not the field should be aligned with other inline fields.
image()
Specs
Represents the image of an embed.
urlA link to this image
The following parameters shouldn't be set when sending embeds:
proxy_urlA proxied url of the image
heightThe height of the image.
widthThe width of the image.
provider()
Specs
Represents the provider of an embed.
This is usually comes from a linked resource (youtube video, etc.)
nameThe name of the provider
urlThe source of the provider
Specs
thumbnail()
Specs
thumbnail() :: %Alchemy.Embed.Thumbnail{
height: Integer,
proxy_url: url(),
url: url(),
width: Integer
}
Represents the thumnail of an embed.
urlA link to the thumbnail image.
proxy_urlA proxied link to the thumbnail image
heightThe height of the thumbnail
widthThe width of the thumbnail
url()
Specs
url() :: String.t()
video()
Specs
video() :: %Alchemy.Embed.Video{height: Integer, url: url(), width: Integer}
Represents a video attached to an embed.
Users can't set this themselves.
urlThe source of the video
heightThe height of the video
widthThe width of the video
Link to this section Functions
author(embed, author)
Specs
Adds author information to an embed.
Note that the proxy_icon_url, height, and width fields have no effect,
when using a pre-made Author struct.
Options
nameThe name of the author.
urlThe url of the author.
icon_urlThe url of the icon to display.
Examples
Cogs.def embed do
%Embed{}
|> author(name: "John",
url: "https://discord.com/developers"
icon_url: "http://i.imgur.com/3nuwWCB.jpg")
|> Embed.send
end
color(embed, integer)
Specs
Sets the color of an embed
Color should be 3 byte integer, with each byte representing a single
color component; i.e. 0xRrGgBb
Examples
Cogs.def embed do
{:ok, message} =
%Embed{description: "the best embed"}
|> color(0xc13261)
|> Embed.send
Process.sleep(2000)
Client.edit_embed(message, embed |> color(0x5aa4d4))
end
description(embed, string)
Specs
Adds a description to an embed.
Cogs.def embed(description) do
%Embed{}
|> title("generic title")
|> description(description)
|> Embed.send
end
field(embed, name, value, options \\ [])
Adds a field to an embed.
Fields are appended when using this method, so the order you pipe them in,
is the order they'll end up when sent. The name and value must be non empty
strings. You can have a maximum of 25 fields.
Parameters
nameThe title of the embed.
valueThe text of the field
Options
inlineWhen setting this to
true, up to 3 fields can appear side by side, given they are all inlined.
Examples
%Embed{}
|> field("Field1", "the best field!")
|> field("Inline1", "look a field ->")
|> field("Inline2", "<- look a field")
image(embed, url)
Specs
Sets the main image of the embed.
Examples
%Embed{}
|> image("http://i.imgur.com/4AiXzf8.jpg")
Sends an embed to the same channel as the message triggering a command.
This macro can't be used outside of Alchemy.Cogs commands.
See Alchemy.Client.send_message/3 for a list of options that can be
passed to this macro.
Examples
Cogs.def blue do
%Embed{}
|> color(0x1d3ad1)
|> description("Hello!")
|> Embed.send("Here's an embed, and a file", file: "foo.txt")
end
thumbnail(embed, url)
Specs
Adds a thumbnail to an embed.
Examples
%Embed{}
|> thumbnail("http://i.imgur.com/4AiXzf8.jpg")
timestamp(embed, time)
Specs
timestamp(t(), DateTime.t()) :: DateTime.t()
Adds a timestamp to an embed.
Note that the Datetime object will get converted to an iso8601 formatted string.
Examples
%Embed{} |> timestamp(DateTime.utc_now())
title(embed, string)
Specs
Adds a title to an embed.
Examples
Cogs.def title(string) do
%Embed{}
|> title(string)
|> Embed.send
end
url(embed, url)
Specs
Sets the url for an embed.
Examples
Cogs.def embed(url) do
%Embed{}
|> url(url)
|> Embed.send
end