EDA.Mention (EDA v0.3.0)

Copy Markdown View Source

Discord mention and timestamp formatting helpers.

Generates the special syntax Discord uses to render mentions, channels, roles, emojis, and timestamps in messages.

Unlike EDA.User.mention/1 or EDA.Role.mention/1 which work on structs, these functions accept raw IDs directly — useful when you only have an ID string without fetching the full entity.

Examples

import EDA.Mention

user("123456")               #=> "<@123456>"
channel("789")               #=> "<#789>"
role("456")                  #=> "<@&456>"
timestamp(1_700_000_000, :R) #=> "<t:1700000000:R>"

Summary

Functions

Formats a channel mention.

Formats a custom emoji.

Formats a role mention.

Formats a Unix timestamp for Discord rendering.

Formats a user mention.

Functions

channel(id)

@spec channel(String.t() | integer()) :: String.t()

Formats a channel mention.

Examples

EDA.Mention.channel("123456789")  #=> "<#123456789>"

emoji(name, id, animated \\ false)

@spec emoji(String.t(), String.t() | integer(), boolean()) :: String.t()

Formats a custom emoji.

Examples

EDA.Mention.emoji("wave", "123456")         #=> "<:wave:123456>"
EDA.Mention.emoji("wave", "123456", true)    #=> "<a:wave:123456>"

role(id)

@spec role(String.t() | integer()) :: String.t()

Formats a role mention.

Examples

EDA.Mention.role("123456789")  #=> "<@&123456789>"

timestamp(unix, style \\ nil)

@spec timestamp(integer(), atom()) :: String.t()

Formats a Unix timestamp for Discord rendering.

Discord will render the timestamp in the user's local timezone.

Styles

StyleExample outputAtom
Short time4:20 PM:t
Long time4:20:30 PM:T
Short date11/14/2023:d
Long dateNovember 14, 2023:D
Short date/timeNovember 14, 2023 4:20 PM:f
Long date/timeTuesday, November 14, 2023 4:20 PM:F
Relative2 hours ago:R

Examples

EDA.Mention.timestamp(1_700_000_000)       #=> "<t:1700000000>"
EDA.Mention.timestamp(1_700_000_000, :R)   #=> "<t:1700000000:R>"
EDA.Mention.timestamp(1_700_000_000, :f)   #=> "<t:1700000000:f>"

user(id)

@spec user(String.t() | integer()) :: String.t()

Formats a user mention.

Examples

EDA.Mention.user("123456789")  #=> "<@123456789>"