Skip to content
Jennifer Programming Language

discord API reference

Post messages to a Discord channel through a channel Webhook, on top of the http client - a sibling of gotify / slack. send(webhookUrl, content) posts a plain message; the message builder assembles a richer payload from embeds (embed, plus embedField / embedFooter / embedAuthor) and optional webhook identity overrides (username / avatar), and sendMessage posts it. Needs the default jennifer binary (uses net via http). The webhook URL is a secret belonging to the caller - read it from the environment or a config file; never commit it.

Import with import "discord.j" as discord;. See the discord guide for prose and examples.

Functions

discord.avatar(m as Message, url as string)

Set a per-message avatar override (the image Discord shows instead of the webhook's configured avatar). Returns a fresh message.

Parameters

  • m {Message} - the message
  • url {string} - the avatar image URL

Returns {Message} - a message with the avatar override set

discord.content(m as Message, content as string)

Set the top-level message content. Returns a fresh message.

Parameters

  • m {Message} - the message
  • content {string} - the content text

Returns {Message} - a message with the content set

discord.embed(m as Message, title as string, description as string, color as int)

Add an embed (a titled, coloured card). color is a decimal RGB integer (e.g. 3066993 for green). At least one of title / description should be non-empty. Returns a fresh message.

Parameters

  • m {Message} - the message
  • title {string} - the embed title
  • description {string} - the embed body (Discord markdown)
  • color {int} - the left-bar colour as a decimal RGB integer

Returns {Message} - a message with the embed appended

discord.embedAuthor(m as Message, name as string)

Set the author name on the most recent embed. Throws if the message has no embed yet. Returns a fresh message.

Parameters

  • m {Message} - the message
  • name {string} - the author name

Returns {Message} - a message whose latest embed gained the author

discord.embedField(m as Message, name as string, value as string, inline as bool)

Add a field (a name / value pair, optionally inline) to the most recent embed. Throws if the message has no embed yet. Returns a fresh message.

Parameters

  • m {Message} - the message
  • name {string} - the field name (bold heading)
  • value {string} - the field value (Discord markdown)
  • inline {bool} - true to let Discord pack this field beside others

Returns {Message} - a message whose latest embed gained the field

discord.embedFooter(m as Message, text as string)

Set the footer text on the most recent embed. Throws if the message has no embed yet. Returns a fresh message.

Parameters

  • m {Message} - the message
  • text {string} - the footer text

Returns {Message} - a message whose latest embed gained the footer

discord.message()

Start an empty rich message (no content, no embeds, default identity).

Returns {Message} - a fresh message

discord.render(m as Message)

Render a message to its JSON payload string.

Parameters

  • m {Message} - the message

Returns {string} - the JSON payload Discord expects

discord.send(webhookUrl as string, content as string)

Post a plain-text message to a Discord Webhook.

Parameters

  • webhookUrl {string} - the channel Webhook URL
  • content {string} - the message content (Discord markdown)

Returns {http.Response} - Discord answers 204 No Content on success

discord.sendMessage(webhookUrl as string, m as Message)

Post a built rich message to a Discord Webhook.

Parameters

  • webhookUrl {string} - the channel Webhook URL
  • m {Message} - the message to send

Returns {http.Response} - Discord answers 204 No Content on success

discord.username(m as Message, name as string)

Set a per-message username override (the name Discord shows instead of the webhook's configured name). Returns a fresh message.

Parameters

  • m {Message} - the message
  • name {string} - the display name to show

Returns {Message} - a message with the username override set

Structs

discord.Embed

One embed under construction: the title / description / colour card plus the optional field list, footer, and author. The fields entries and the footer / author strings are pre-rendered JSON fragments ("" to omit).

FieldTypeDescription
titlestringthe embed title
descriptionstringthe embed body (Discord markdown)
colorintthe left-bar colour as a decimal RGB integer
fieldslist of stringpre-rendered field JSON fragments
footerstring"" or a pre-rendered footer JSON object
authorstring"" or a pre-rendered author JSON object

discord.Message

A rich message under construction: a top-level content string, a list of embeds, and optional webhook-identity overrides (username / avatar, each "" to omit).

FieldTypeDescription
contentstringthe message content ("" to omit; embeds must then be present)
embedslist of Embedthe message embeds
usernamestring"" or a per-message username override
avatarstring"" or a per-message avatar image URL override