webhook

package
v2.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2021 License: ISC Imports: 9 Imported by: 6

Documentation

Overview

Package webhook provides means to interact with webhooks directly and not through the bot API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Client is the httputil.Client used to call Discord's API.
	*httputil.Client
	// ID is the id of the webhook.
	ID discord.WebhookID
	// Token is the token of the webhook.
	Token string
}

Client is the client used to interact with a webhook.

func New

func New(id discord.WebhookID, token string) *Client

New creates a new Client using the passed token and id.

func NewCustom

func NewCustom(id discord.WebhookID, token string, c *httputil.Client) *Client

NewCustom creates a new Client creates a new Client using the passed token and ID and makes API calls using the passed httputil.Client

func (*Client) Delete

func (c *Client) Delete() error

Delete deletes a webhook permanently.

func (*Client) DeleteMessage

func (c *Client) DeleteMessage(messageID discord.MessageID) error

DeleteMessage deletes a message that was previously created by the same webhook.

func (*Client) EditMessage

func (c *Client) EditMessage(messageID discord.MessageID, data EditMessageData) error

EditMessage edits a previously-sent webhook message from the same webhook.

func (*Client) Execute

func (c *Client) Execute(data ExecuteData) (err error)

Execute sends a message to the webhook, but doesn't wait for the message to get created. This is generally faster, but only applicable if no further interaction is required.

func (*Client) ExecuteAndWait

func (c *Client) ExecuteAndWait(data ExecuteData) (*discord.Message, error)

ExecuteAndWait executes the webhook, and waits for the generated discord.Message to be returned.

func (*Client) Get

func (c *Client) Get() (*discord.Webhook, error)

Get gets the webhook.

func (*Client) Modify

func (c *Client) Modify(data api.ModifyWebhookData) (*discord.Webhook, error)

Modify modifies the webhook.

type EditMessageData

type EditMessageData struct {
	// Content are the message contents. They may be up to 2000 characters
	// characters long.
	Content option.NullableString `json:"content,omitempty"`
	// Embeds is an array of up to 10 discord.Embeds.
	Embeds *[]discord.Embed `json:"embeds,omitempty"`
	// AllowedMentions are the AllowedMentions for the message.
	AllowedMentions *api.AllowedMentions `json:"allowed_mentions,omitempty"`
}

https://discord.com/developers/docs/resources/webhook#edit-webhook-message-jsonform-params

type ExecuteData

type ExecuteData struct {
	// Content are the message contents (up to 2000 characters).
	//
	// Required: one of content, file, embeds
	Content string `json:"content,omitempty"`

	// Username overrides the default username of the webhook
	Username string `json:"username,omitempty"`
	// AvatarURL overrides the default avatar of the webhook.
	AvatarURL discord.URL `json:"avatar_url,omitempty"`

	// TTS is true if this is a TTS message.
	TTS bool `json:"tts,omitempty"`
	// Embeds contains embedded rich content.
	//
	// Required: one of content, file, embeds
	Embeds []discord.Embed `json:"embeds,omitempty"`

	// Files represents a list of files to upload. This will not be JSON-encoded
	// and will only be available through WriteMultipart.
	Files []sendpart.File `json:"-"`

	// AllowedMentions are the allowed mentions for the message.
	AllowedMentions *api.AllowedMentions `json:"allowed_mentions,omitempty"`
}

https://discord.com/developers/docs/resources/webhook#execute-webhook-jsonform-params

func (ExecuteData) NeedsMultipart

func (data ExecuteData) NeedsMultipart() bool

NeedsMultipart returns true if the ExecuteWebhookData has files.

func (ExecuteData) WriteMultipart

func (data ExecuteData) WriteMultipart(body *multipart.Writer) error

WriteMultipart writes the webhook data into the given multipart body. It does not close body.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL