EDA.API.Soundboard (EDA v0.5.0-beta.2)

Copy Markdown View Source

REST API endpoints for soundboard sounds.

All functions return raw maps: {:ok, map} or {:error, reason}. EDA.SoundboardSound wraps the reads in structs.

A soundboard sound is either one of Discord's defaults, available everywhere, or belongs to a guild. Guild sounds are managed with create/2, modify/3 and delete/3, which need the CREATE_GUILD_EXPRESSIONS or MANAGE_GUILD_EXPRESSIONS permission, and played into a voice channel with send_sound/3.

The create, modify and delete routes accept :reason, sent as the audit log reason.

Summary

Functions

Creates a guild soundboard sound. Requires CREATE_GUILD_EXPRESSIONS.

Lists the default soundboard sounds, available to every user.

Deletes a guild soundboard sound. Same permissions as modify/3.

Gets one of a guild's soundboard sounds.

Lists a guild's soundboard sounds.

Modifies a guild soundboard sound.

Plays a soundboard sound into a voice channel.

Functions

create(guild_id, opts)

@spec create(String.t() | integer(), keyword() | map()) ::
  {:ok, map()} | {:error, term()}

Creates a guild soundboard sound. Requires CREATE_GUILD_EXPRESSIONS.

Options

  • :name — required, 2–32 characters
  • :sound — required: a path, raw MP3 or Ogg bytes, or a data URI; see EDA.SoundData. At most 512 KiB and 5.2 seconds
  • :volume — 0 to 1, defaults to 1
  • :emoji_id — a custom emoji for the sound
  • :emoji_name — or a standard emoji, as its unicode character
  • :reason — audit log reason

Example

EDA.API.Soundboard.create(guild_id, name: "airhorn", sound: "priv/airhorn.mp3", emoji_name: "📯")

default_sounds()

@spec default_sounds() :: {:ok, [map()]} | {:error, term()}

Lists the default soundboard sounds, available to every user.

GET /soundboard-default-sounds

delete(guild_id, sound_id, opts \\ [])

@spec delete(String.t() | integer(), String.t() | integer(), keyword()) ::
  :ok | {:error, term()}

Deletes a guild soundboard sound. Same permissions as modify/3.

Options

  • :reason — audit log reason

get(guild_id, sound_id)

@spec get(String.t() | integer(), String.t() | integer()) ::
  {:ok, map()} | {:error, term()}

Gets one of a guild's soundboard sounds.

list(guild_id)

@spec list(String.t() | integer()) :: {:ok, [map()]} | {:error, term()}

Lists a guild's soundboard sounds.

GET /guilds/{guild_id}/soundboard-sounds. Discord wraps the list as %{"items" => [...]}; this returns the list itself. Each sound carries its creator in "user" only when the bot has CREATE_GUILD_EXPRESSIONS or MANAGE_GUILD_EXPRESSIONS.

modify(guild_id, sound_id, opts)

@spec modify(String.t() | integer(), String.t() | integer(), keyword() | map()) ::
  {:ok, map()} | {:error, term()}

Modifies a guild soundboard sound.

A sound the bot created needs CREATE_GUILD_EXPRESSIONS or MANAGE_GUILD_EXPRESSIONS; any other needs MANAGE_GUILD_EXPRESSIONS. The audio itself cannot be changed.

Options

:name, :volume, :emoji_id, :emoji_name and :reason, as for create/2. A nil volume or emoji clears it.

send_sound(channel_id, sound_id, opts \\ [])

@spec send_sound(String.t() | integer(), String.t() | integer(), keyword()) ::
  :ok | {:error, term()}

Plays a soundboard sound into a voice channel.

POST /channels/{channel_id}/send-soundboard-sound. Discord only accepts it from a user in that channel, and neither muted, deafened nor suppressed — so the bot must have joined it with EDA.Voice.join/2 first. Requires SPEAK and USE_SOUNDBOARD, plus USE_EXTERNAL_SOUNDS for a sound from another guild. Everyone connected receives a VOICE_CHANNEL_EFFECT_SEND event.

Options

  • :source_guild_id — the guild the sound belongs to, required to play one from another guild. Not needed for a default sound or one from this channel's guild

Example

EDA.API.Soundboard.send_sound(channel_id, "1")   # a default sound