Nostrum v0.4.0 Nostrum.Struct.Emoji View Source

Struct representing a Discord emoji.

Mentioning Emojis in Messages

A Nostrum.Struct.Emoji can be mentioned in message content using the String.Chars protocol or mention/1.

emoji = %Nostrum.Struct.Emoji{id: 437093487582642177, name: "foxbot"}
Nostrum.Api.create_message!(184046599834435585, "#{emoji}")
%Nostrum.Struct.Message{content: "<:foxbot:437093487582642177>"}

emoji = %Nostrum.Struct.Emoji{id: 436885297037312001, name: "tealixir"}
Nostrum.Api.create_message!(280085880452939778, "#{Nostrum.Struct.Emoji.mention(emoji)}")
%Nostrum.Struct.Message{content: "<:tealixir:436885297037312001>"}

Using Emojis in the Api

A Nostrum.Struct.Emoji can be used in Nostrum.Api by using its api name or the struct itself.

emoji = %Nostrum.Struct.Emoji{id: 436885297037312001, name: "tealixir"}
Nostrum.Api.create_reaction(381889573426429952, 436247584349356032, Nostrum.Struct.Emoji.api_name(emoji))
{:ok}

emoji = %Nostrum.Struct.Emoji{id: 436189601820966923, name: "elixir"}
Nostrum.Api.create_reaction(381889573426429952, 436247584349356032, emoji)
{:ok}

See Nostrum.Struct.Emoji.api_name/0 for more information.

Link to this section Summary

Types

Whether this emoji is animated

Emoji string to be used with the Discord API.

Id of the emoji

Whether this emoji is managed

Name of the emoji

Whether this emoji must be wrapped in colons

Roles this emoji is whitelisted to

t()

User that created this emoji

Functions

Formats an emoji struct into its Nostrum.Struct.Emoji.api_name/0.

Returns the url of a custom emoji's image. If the emoji is not a custom one, returns nil.

Formats an Nostrum.Struct.Emoji into a mention.

Link to this section Types

Link to this type

animated() View Source
animated() :: boolean() | nil

Whether this emoji is animated

Link to this type

api_name() View Source
api_name() :: String.t()

Emoji string to be used with the Discord API.

Some API endpoints take an emoji. If it is a custom emoji, it must be structured as "id:name". If it is an unicode emoji, it can be structured as any of the following:

  • "name"
  • A base 16 unicode emoji string.

api_name/1 is a convenience function that returns a Nostrum.Struct.Emoji's api name.

Examples

# Custom Emojis
"nostrum:431890438091489"

# Unicode Emojis
"👍"
"\xF0\x9F\x98\x81"
"\u2b50"

Id of the emoji

Link to this type

managed() View Source
managed() :: boolean() | nil

Whether this emoji is managed

Name of the emoji

Link to this type

require_colons() View Source
require_colons() :: boolean() | nil

Whether this emoji must be wrapped in colons

Roles this emoji is whitelisted to

Link to this type

t() View Source
t() :: %Nostrum.Struct.Emoji{
  animated: animated(),
  id: id(),
  managed: managed(),
  name: name(),
  require_colons: require_colons(),
  roles: roles(),
  user: user()
}

User that created this emoji

Link to this section Functions

Link to this function

api_name(emoji) View Source
api_name(t()) :: api_name()

Formats an emoji struct into its Nostrum.Struct.Emoji.api_name/0.

Examples

iex> emoji = %Nostrum.Struct.Emoji{name: "Γ¡É"}
...> Nostrum.Struct.Emoji.api_name(emoji)
"Γ¡É"

iex> emoji = %Nostrum.Struct.Emoji{id: 437093487582642177, name: "foxbot"}
...> Nostrum.Struct.Emoji.api_name(emoji)
"foxbot:437093487582642177"
Link to this function

image_url(emoji) View Source
image_url(t()) :: String.t() | nil

Returns the url of a custom emoji's image. If the emoji is not a custom one, returns nil.

Examples

iex> emoji = %Nostrum.Struct.Emoji{id: 450225070569291776}
iex> Nostrum.Struct.Emoji.image_url(emoji)
"https://cdn.discordapp.com/emojis/450225070569291776.png"

iex> emoji = %Nostrum.Struct.Emoji{id: 406140226998894614, animated: true}
iex> Nostrum.Struct.Emoji.image_url(emoji)
"https://cdn.discordapp.com/emojis/406140226998894614.gif"

iex> emoji = %Nostrum.Struct.Emoji{id: nil, name: "Γ¡É"}
iex> Nostrum.Struct.Emoji.image_url(emoji)
nil
Link to this function

mention(emoji) View Source
mention(t()) :: String.t()

Formats an Nostrum.Struct.Emoji into a mention.

Examples

iex> emoji = %Nostrum.Struct.Emoji{name: "👍"}
...> Nostrum.Struct.Emoji.mention(emoji)
"👍"

iex> emoji = %Nostrum.Struct.Emoji{id: 436885297037312001, name: "tealixir"}
...> Nostrum.Struct.Emoji.mention(emoji)
"<:tealixir:436885297037312001>"

iex> emoji = %Nostrum.Struct.Emoji{id: 437016804309860372, name: "blobseizure", animated: true}
...> Nostrum.Struct.Emoji.mention(emoji)
"<a:blobseizure:437016804309860372>"