alchemy v0.1.9 Alchemy.Webhook

Summary

Functions

Creates a new webhook in a channel

Deletes a webhook

Modifies the settings of a webhook

Returns a list of all webhooks in a channel.

Example

{:ok, [%Webhook{} | _]} = Task.await Webhook.in_channel("6666")

Returns a list of all webhooks in a guild.

Example

{:ok, [%Webhook{} | _]} = Task.await Webhook.in_guild("99999")

Sends a message to a webhook

Types

t :: %Alchemy.Webhook{avatar: String.t | nil, channel_id: snowflake, guild_id: snowflake | nil, id: snowflake, name: String.t | nil, token: String.t, user: Alchemy.User.t | nil}

Functions

create(channel_id, name, options \\ [])

Specs

create(snowflake, String.t, [{:avatar, String.t}]) ::
  {:ok, Alchemy.Webhook.t} |
  {:error, term}

Creates a new webhook in a channel.

The name parameter is mandatory, and specifies the name of the webhook. of course.

Options

  • avatar A link to a 128x128 image to act as the avatar of the webhook.

Examples

{:ok, hook} = Task.await Webhook.create("66666", "The Devil")
delete(webhook)

Specs

delete(Alchemy.Webhook.t) ::
  {:ok, Alchemy.Webhook.t} |
  {:error, term}

Deletes a webhook.

All you need for this is the webhook itself.

Examples

{:ok, wh} = Task.await Webhook.create("666", "Captain Hook")
Webhook.delete(wh)
edit(webhook, options)

Specs

edit(Alchemy.Webhook.t, name: String.t, avatar: String.t) ::
  {:ok, Alchemy.Webhook.t} |
  {:error, term}

Modifies the settings of a webhook.

Note that the user field of the webhook will be missing.

Options

  • name The name of the webhook.
  • avatar A link to a 128x128 icon image.

Examples

{:ok, hook} = Task.await Webhook.create("6666", "Captian Hook")
# Let's fix that typo:
Webhook.edit(hook, name: "Captain Hook")
in_channel(channel_id)

Specs

in_channel(snowflake) ::
  {:ok, [Alchemy.Webhook.t]} |
  {:error, term}

Returns a list of all webhooks in a channel.

Example

{:ok, [%Webhook{} | _]} = Task.await Webhook.in_channel("6666")
in_guild(guild_id)

Specs

in_guild(atom) ::
  {:ok, [Alchemy.Webhook.t]} |
  {:error, term}

Returns a list of all webhooks in a guild.

Example

{:ok, [%Webhook{} | _]} = Task.await Webhook.in_guild("99999")
send(webhook, arg, options \\ [])

Specs

send(Alchemy.Webhook.t, {:embed, Alchemy.Embed.t} | {:content, String.t}, avatar_url: String.t, username: String.t, tts: Boolean) ::
  {:ok, nil} |
  {:error, term}

Sends a message to a webhook.

type must be one of :embed, :content; :embed requiring an Embed.t struct, and :content requiring a string.

Options

  • avatar_url A link to an image to replace the one the hook has, for this message.
  • username The username to override to hook’s, for this message.
  • tts When set to true, will make the message TTS

Examples

{:ok, hook} = Task.await Webhook.create("66", "Captain Hook")
Webhook.send(hook, {content: "ARRRRRGH!"})

For a more elaborate example:

user = Cache.user()
embed = %Embed{}
        |> description("I'm commandeering this vessel!!!")
        |> color(0x3a83b8)
Webhook.send(hook, {:embed, embed},
             avatar_url: User.avatar_url(user),
             username: user.username)