View Source Nostrum.Struct.Emoji (Nostrum v0.8.0)

Struct representing a Discord emoji.

mentioning-emojis-in-messages

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

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

@type animated() :: boolean() | nil

Whether this emoji is animated

@type 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

Examples

# Custom Emojis
"nostrum:431890438091489"

# Unicode Emojis
"👍"
"\xF0\x9F\x98\x81"
"\u2b50"
@type id() :: Nostrum.Snowflake.t() | nil

Id of the emoji

@type managed() :: boolean() | nil

Whether this emoji is managed

@type name() :: String.t()

Name of the emoji

@type require_colons() :: boolean() | nil

Whether this emoji must be wrapped in colons

@type roles() :: [Nostrum.Struct.Guild.Role.id()] | nil

Roles this emoji is whitelisted to

@type t() :: %Nostrum.Struct.Emoji{
  animated: animated(),
  id: id(),
  managed: managed(),
  name: name(),
  require_colons: require_colons(),
  roles: roles(),
  user: user()
}
@type user() :: Nostrum.Struct.User.t() | nil

User that created this emoji

Link to this section Functions

@spec api_name(t()) :: api_name()

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

examples

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"
@spec 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

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
@spec mention(t()) :: String.t()

Formats an Nostrum.Struct.Emoji into a mention.

examples

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>"