Nostrum.Api.Webhook (nostrum v0.11.0-dev)

View Source

Functions for interacting with the Discord API's webhook endpoints.

See: https://discord.com/developers/docs/resources/webhook

Summary

Functions

Edits a message previously created by the same webhook, args are the same as execute/3, however all fields are optional.

Gets a webhook by id.

Retrieves the original message of a webhook.

Gets a webhook by id and token.

Types

matrix()

(since 0.10.1)
@type matrix() :: m1() | m2() | m3()

Functions

create(channel_id, args, reason \\ nil)

(since 0.10.1)

Creates a webhook.

Parameters

  • channel_id - Id of the channel to send the message to.
  • args - Map with the following required keys:
    • name - Name of the webhook.
    • avatar - Base64 128x128 jpeg image for the default avatar.
  • reason - An optional reason for the guild audit log.

delete(webhook_id, reason \\ nil)

(since 0.10.1)

Deletes a webhook.

Parameters

  • webhook_id - Id of webhook to delete.
  • reason - An optional reason for the guild audit log.

edit_message(webhook_id, webhook_token, message_id, args)

(since 1.x.x)

Edits a message previously created by the same webhook, args are the same as execute/3, however all fields are optional.

execute(webhook_id, webhook_token, args, wait \\ false)

(since 0.10.1)

Executes a webhook.

Parameters

  • webhook_id - Id of the webhook to execute.
  • webhook_token - Token of the webhook to execute.
  • args - Map with the following allowed keys:
    • content - Message content.
    • files - List of Files to send.
    • embeds - List of embeds to send.
    • username - Overrides the default name of the webhook.
    • avatar_url - Overrides the default avatar of the webhook.
    • tts - Whether the message should be read over text to speech.
    • flags - Bitwise flags.
    • thread_id - Send a message to the specified thread within the webhook's channel.
    • allowed_mentions - Mentions to allow in the webhook message
  • wait - Whether to return an error or not. Defaults to false.

Note: If wait is true, this method will return a Message.t() on success.

At least one of content, files or embeds should be supplied in the args parameter.

execute_git(webhook_id, webhook_token, wait \\ false)

(since 0.10.1)

Executes a git webhook.

Parameters

  • webhook_id - Id of the webhook to execute.
  • webhook_token - Token of the webhook to execute.

execute_slack(webhook_id, webhook_token, wait \\ false)

(since 0.10.1)

Executes a slack webhook.

Parameters

  • webhook_id - Id of the webhook to execute.
  • webhook_token - Token of the webhook to execute.

get(webhook_id)

(since 0.10.1)

Gets a webhook by id.

Parameters

  • webhook_id - Id of the webhook to get.

get_message(webhook, message_id)

(since 1.x.x)

Retrieves the original message of a webhook.

get_with_token(webhook_id, webhook_token)

(since 0.10.1)

Gets a webhook by id and token.

This method is exactly like get/1 but does not require authentication.

Parameters

  • webhook_id - Id of the webhook to get.
  • webhook_token - Token of the webhook to get.

modify(webhook_id, args, reason \\ nil)

(since 0.10.1)
@spec modify(
  Nostrum.Struct.Webhook.id(),
  %{
    optional(:name) => String.t(),
    optional(:avatar) => String.t() | nil,
    optional(:channel_id) => Nostrum.Struct.Channel.id()
  },
  Nostrum.Struct.Guild.AuditLogEntry.reason()
) :: Nostrum.Api.error() | {:ok, Nostrum.Struct.Webhook.t()}

Modifies a webhook.

Parameters

  • webhook_id - Id of the webhook to modify.
  • args - Map with the following optional keys:
    • name - Name of the webhook.
    • avatar - Base64 128x128 jpeg image for the default avatar.
    • channel_id - The new channel this webhook should be moved to.
  • reason - An optional reason for the guild audit log.

Reference

See the Discord developer docs.

modify_with_token(webhook_id, webhook_token, args, reason \\ nil)

(since 0.10.1)
@spec modify_with_token(
  Nostrum.Struct.Webhook.id(),
  Nostrum.Struct.Webhook.token(),
  %{
    optional(:name) => String.t(),
    optional(:avatar) => String.t() | nil,
    optional(:channel_id) => Nostrum.Struct.Channel.id()
  },
  Nostrum.Struct.Guild.AuditLogEntry.reason()
) :: Nostrum.Api.error() | {:ok, Nostrum.Struct.Webhook.t()}

Modifies a webhook with a token.

This method is exactly like modify_webhook/1 but does not require authentication.

Parameters

  • webhook_id - Id of the webhook to modify.
  • webhook_token - Token of the webhook to get.
  • args - Map with the following optional keys:
    • name - Name of the webhook.
    • avatar - Base64 128x128 jpeg image for the default avatar.
    • channel_id - The new channel this webhook should be moved to.
  • reason - An optional reason for the guild audit log.

Reference

See the Discord developer docs.