Nostrum.Struct.Embed behaviour (Nostrum v0.4.6) View Source
Functions that work on Discord embeds.
Building Embeds
Nostrum.Struct.Embeds can be built using this module's builder functions
or standard Map syntax:
iex> import Nostrum.Struct.Embed
...> embed =
...> %Nostrum.Struct.Embed{}
...> |> put_title("craig")
...> |> put_description("nostrum")
...> |> put_url("https://google.com/")
...> |> put_timestamp("2016-05-05T21:04:13.203Z")
...> |> put_color(431_948)
...> |> put_field("Field 1", "Test")
...> |> put_field("Field 2", "More test", true)
...> embed
%Nostrum.Struct.Embed{
title: "craig",
description: "nostrum",
url: "https://google.com/",
timestamp: "2016-05-05T21:04:13.203Z",
color: 431_948,
fields: [
%Nostrum.Struct.Embed.Field{name: "Field 1", value: "Test"},
%Nostrum.Struct.Embed.Field{name: "Field 2", value: "More test", inline: true}
]
}Using structs
You can also create Nostrum.Struct.Embeds from structs, by using the
Nostrum.Struct.Embed module. Here's how the example above could be build using structs
defmodule MyApp.MyStruct do
use Nostrum.Struct.Embed
defstruct []
def title(_), do: "craig"
def description(_), do: "nostrum"
def url(_), do: "https://google.com/"
def timestamp(_), do: "2016-05-05T21:04:13.203Z"
def color(_), do: 431_948
def fields(_) do
[
%Nostrum.Struct.Embed.Field{name: "Field 1", value: "Test"},
%Nostrum.Struct.Embed.Field{name: "Field 2", value: "More test", inline: true}
]
end
end
iex> Nostrum.Struct.Embed.from(%MyApp.MyStruct{})
%Nostrum.Struct.Embed{
title: "craig",
description: "nostrum",
url: "https://google.com/",
timestamp: "2016-05-05T21:04:13.203Z",
color: 431_948,
fields: [
%Nostrum.Struct.Embed.Field{name: "Field 1", value: "Test"},
%Nostrum.Struct.Embed.Field{name: "Field 2", value: "More test", inline: true}
]
}See this modules callbacks for a list of all the functions that can be implemented.
The implementation of these callbacks is optional. Not implemented functions will simply be ignored.
Link to this section Summary
Types
Author information
Color code of the embed
Description of the embed
Fields information
Footer information
Image information
Provider information
Thumbnail information
Timestamp of embed content
Title of the embed
Type of the embed
Url of the embed
Video information
Functions
Create an embed from a struct that implements the Nostrum.Struct.Embed behaviour
Puts a Nostrum.Struct.Embed.Author under :author in embed.
Puts the given value under :color in embed.
Puts the given value under :description in embed.
Adds a Nostrum.Struct.Embed.Field under :fields in embed.
Puts a Nostrum.Struct.Embed.Footer under :footer in embed.
Puts a Nostrum.Struct.Embed.Image under :image in embed.
Puts a Nostrum.Struct.Embed.Thumbnail under :thumbnail in embed.
Puts the given value under :timestamp in embed.
Puts the given value under :title in embed.
Puts the given value under :url in embed.
Link to this section Types
Specs
author() :: Nostrum.Struct.Embed.Author.t() | nil
Author information
Specs
color() :: integer() | nil
Color code of the embed
Specs
description() :: String.t() | nil
Description of the embed
Specs
fields() :: [Nostrum.Struct.Embed.Field.t()] | nil
Fields information
Specs
image() :: Nostrum.Struct.Embed.Image.t() | nil
Image information
Specs
provider() :: Nostrum.Struct.Embed.Provider.t() | nil
Provider information
Specs
Specs
thumbnail() :: Nostrum.Struct.Embed.Thumbnail.t() | nil
Thumbnail information
Specs
timestamp() :: String.t() | nil
Timestamp of embed content
Specs
title() :: String.t() | nil
Title of the embed
Specs
type() :: String.t() | nil
Type of the embed
Specs
url() :: String.t() | nil
Url of the embed
Specs
video() :: Nostrum.Struct.Embed.Video.t() | nil
Video information
Link to this section Functions
Create an embed from a struct that implements the Nostrum.Struct.Embed behaviour
Specs
put_author( t(), Nostrum.Struct.Embed.Author.name(), Nostrum.Struct.Embed.Author.url(), Nostrum.Struct.Embed.Author.icon_url() ) :: t()
Puts a Nostrum.Struct.Embed.Author under :author in embed.
Examples
iex> embed = %Nostrum.Struct.Embed{}
...> Nostrum.Struct.Embed.put_author(embed, "skippi", "https://github.com/skippi", nil)
%Nostrum.Struct.Embed{
author: %Nostrum.Struct.Embed.Author{
name: "skippi",
url: "https://github.com/skippi",
icon_url: nil
}
}
Specs
Puts the given value under :color in embed.
Examples
iex> embed = %Nostrum.Struct.Embed{}
...> Nostrum.Struct.Embed.put_color(embed, 431948)
%Nostrum.Struct.Embed{color: 431948}
Specs
put_description(t(), description()) :: t()
Puts the given value under :description in embed.
Examples
iex> embed = %Nostrum.Struct.Embed{}
...> Nostrum.Struct.Embed.put_description(embed, "An elixir library for the discord API.")
%Nostrum.Struct.Embed{description: "An elixir library for the discord API."}
Specs
put_field( t(), Nostrum.Struct.Embed.Field.name(), Nostrum.Struct.Embed.Field.value(), Nostrum.Struct.Embed.Field.inline() ) :: t()
Adds a Nostrum.Struct.Embed.Field under :fields in embed.
Examples
iex> embed = %Nostrum.Struct.Embed{}
...> Nostrum.Struct.Embed.put_field(embed, "First User", "b1nzy")
%Nostrum.Struct.Embed{
fields: [
%Nostrum.Struct.Embed.Field{name: "First User", value: "b1nzy"}
]
}
iex> embed = %Nostrum.Struct.Embed{
...> fields: [
...> %Nostrum.Struct.Embed.Field{name: "First User", value: "b1nzy"}
...> ]
...> }
...> Nostrum.Struct.Embed.put_field(embed, "Second User", "Danny")
%Nostrum.Struct.Embed{
fields: [
%Nostrum.Struct.Embed.Field{name: "First User", value: "b1nzy"},
%Nostrum.Struct.Embed.Field{name: "Second User", value: "Danny"}
]
}
Specs
put_image(t(), Nostrum.Struct.Embed.Image.url()) :: t()
Puts a Nostrum.Struct.Embed.Image under :image in embed.
Examples
iex> embed = %Nostrum.Struct.Embed{}
...> Nostrum.Struct.Embed.put_image(embed, "https://discord.com/assets/af92e60c16b7019f34a467383b31490a.svg")
%Nostrum.Struct.Embed{
image: %Nostrum.Struct.Embed.Image{
url: "https://discord.com/assets/af92e60c16b7019f34a467383b31490a.svg"
}
}
Specs
put_thumbnail(t(), Nostrum.Struct.Embed.Thumbnail.url()) :: t()
Puts a Nostrum.Struct.Embed.Thumbnail under :thumbnail in embed.
Examples
iex> embed = %Nostrum.Struct.Embed{}
...> Nostrum.Struct.Embed.put_thumbnail(embed, "https://discord.com/assets/af92e60c16b7019f34a467383b31490a.svg")
%Nostrum.Struct.Embed{
thumbnail: %Nostrum.Struct.Embed.Thumbnail{
url: "https://discord.com/assets/af92e60c16b7019f34a467383b31490a.svg"
}
}
Specs
Puts the given value under :timestamp in embed.
Examples
iex> embed = %Nostrum.Struct.Embed{}
...> Nostrum.Struct.Embed.put_timestamp(embed, "2018-04-21T17:33:51.893000Z")
%Nostrum.Struct.Embed{timestamp: "2018-04-21T17:33:51.893000Z"}
Specs
Puts the given value under :title in embed.
Examples
iex> embed = %Nostrum.Struct.Embed{}
...> Nostrum.Struct.Embed.put_title(embed, "nostrum")
%Nostrum.Struct.Embed{title: "nostrum"}
Specs
Puts the given value under :url in embed.
Examples
iex> embed = %Nostrum.Struct.Embed{}
...> Nostrum.Struct.Embed.put_url(embed, "https://github.com/Kraigie/nostrum")
%Nostrum.Struct.Embed{url: "https://github.com/Kraigie/nostrum"}