View Source Nostrum.Struct.Embed behaviour (Nostrum v0.10.4)
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.
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.
Types
@type author() :: Nostrum.Struct.Embed.Author.t() | nil
Author information
@type color() :: integer() | nil
Color code of the embed
@type description() :: String.t() | nil
Description of the embed
@type fields() :: [Nostrum.Struct.Embed.Field.t()] | nil
Fields information
@type image() :: Nostrum.Struct.Embed.Image.t() | nil
Image information
@type provider() :: Nostrum.Struct.Embed.Provider.t() | nil
Provider information
@type thumbnail() :: Nostrum.Struct.Embed.Thumbnail.t() | nil
Thumbnail information
@type timestamp() :: String.t() | nil
Timestamp of embed content
@type title() :: String.t() | nil
Title of the embed
@type type() :: String.t() | nil
Type of the embed
@type url() :: String.t() | nil
Url of the embed
@type video() :: Nostrum.Struct.Embed.Video.t() | nil
Video information
Callbacks
Functions
Create an embed from a struct that implements the Nostrum.Struct.Embed behaviour
@spec 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
}
}
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}
@spec 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."}
@spec 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"}
]
}
@spec 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"
}
}
@spec 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"
}
}
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"}
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"}
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"}