webhook

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 9 Imported by: 46

README

webhook

Webhook module of disgo

Usage

Import the package into your project.

import "github.com/disgoorg/disgo/webhook"

Create a new Webhook by webhook_id and webhook_token. (This WebhookClient should be created once as it holds important state)

client := webhook.New(snowflake.ID("webhookID"), "webhookToken")

client, err := webhook.NewWithURL("webhookURL")

webhook.New takes a vararg of type webhook.ConfigOpt as third argument which lets you pass additional optional parameter like a custom logger, rest client, etc

Optional Arguments
client := webhook.New(snowflake.ID("webhookID"), "webhookToken",
	webhook.WithLogger(logrus.New()),
	webhook.WithDefaultAllowedMentions(discord.AllowedMentions{
		RepliedUser: false,
	}),
)
Send Message

You can send a message as following

client := webhook.New(snowflake.ID("webhookID"), "webhookToken")

message, err := client.CreateContent("hello world!")

message, err := client.CreateEmbeds(discord.NewEmbedBuilder().
	SetDescription("hello world!").
	Build(),
)

message, err := client.CreateMessage(discord.NewWebhookMessageCreateBuilder().
	SetContent("hello world!").
	Build(),
	rest.CreateWebhookMessageParams{},
)

message, err := client.CreateMessage(discord.WebhookMessageCreate{
	Content: "hello world!",
}, rest.CreateWebhookMessageParams{})
Edit Message

Messages can also be edited

client := webhook.New(snowflake.ID("webhookID"), "webhookToken")

message, err := client.UpdateContent("870741249114652722", "hello world!")

message, err := client.UpdateEmbeds("870741249114652722", discord.NewEmbedBuilder().
	SetDescription("hello world!").
	Build(),
)

message, err := client.UpdateMessage("870741249114652722", discord.NewWebhookMessageUpdateBuilder().
	SetContent("hello world!").
	Build(),
	rest.UpdateWebhookMessageParams{},
)

message, err := client.UpdateMessage("870741249114652722", discord.WebhookMessageUpdate{
	Content: json.Ptr("hello world!"),
}, rest.UpdateWebhookMessageParams{})
Delete Message

or deleted

client := webhook.New(snowflake.ID("webhookID"), "webhookToken")

err := client.DeleteMessage("message_id")
Full Example

a full example can be found here

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidWebhookURL = errors.New("invalid webhook URL")

Functions

This section is empty.

Types

type Client

type Client struct {
	ID         snowflake.ID
	Token      string
	Rest       rest.Webhooks
	RestClient rest.Client
	// contains filtered or unexported fields
}

func New added in v0.12.0

func New(id snowflake.ID, token string, opts ...ConfigOpt) *Client

New creates a new Client with the given ID, Token and ConfigOpt(s).

func NewWithURL added in v0.14.1

func NewWithURL(webhookURL string, opts ...ConfigOpt) (*Client, error)

NewWithURL creates a new Client by parsing the given webhookURL for the ID and Token.

func (*Client) Close

func (c *Client) Close(ctx context.Context)

func (*Client) CreateContent

func (c *Client) CreateContent(content string, opts ...rest.RequestOpt) (*discord.Message, error)

func (*Client) CreateEmbeds

func (c *Client) CreateEmbeds(embeds []discord.Embed, opts ...rest.RequestOpt) (*discord.Message, error)

func (*Client) CreateMessage

func (c *Client) CreateMessage(messageCreate discord.WebhookMessageCreate, params rest.CreateWebhookMessageParams, opts ...rest.RequestOpt) (*discord.Message, error)

func (*Client) CreateMessageInThread

func (c *Client) CreateMessageInThread(messageCreate discord.WebhookMessageCreate, threadID snowflake.ID, opts ...rest.RequestOpt) (*discord.Message, error)

func (*Client) DeleteMessage

func (c *Client) DeleteMessage(messageID snowflake.ID, opts ...rest.RequestOpt) error

func (*Client) DeleteMessageInThread

func (c *Client) DeleteMessageInThread(messageID snowflake.ID, threadID snowflake.ID, opts ...rest.RequestOpt) error

func (*Client) DeleteWebhook

func (c *Client) DeleteWebhook(opts ...rest.RequestOpt) error

func (*Client) GetMessage added in v0.18.16

func (c *Client) GetMessage(messageID snowflake.ID, opts ...rest.RequestOpt) (*discord.Message, error)

func (*Client) GetWebhook

func (c *Client) GetWebhook(opts ...rest.RequestOpt) (*discord.IncomingWebhook, error)

func (*Client) URL

func (c *Client) URL() string

func (*Client) UpdateContent

func (c *Client) UpdateContent(messageID snowflake.ID, content string, opts ...rest.RequestOpt) (*discord.Message, error)

func (*Client) UpdateEmbeds

func (c *Client) UpdateEmbeds(messageID snowflake.ID, embeds []discord.Embed, opts ...rest.RequestOpt) (*discord.Message, error)

func (*Client) UpdateMessage

func (c *Client) UpdateMessage(messageID snowflake.ID, messageUpdate discord.WebhookMessageUpdate, params rest.UpdateWebhookMessageParams, opts ...rest.RequestOpt) (*discord.Message, error)

func (*Client) UpdateMessageInThread

func (c *Client) UpdateMessageInThread(messageID snowflake.ID, messageUpdate discord.WebhookMessageUpdate, threadID snowflake.ID, opts ...rest.RequestOpt) (*discord.Message, error)

func (*Client) UpdateWebhook

func (c *Client) UpdateWebhook(webhookUpdate discord.WebhookUpdateWithToken, opts ...rest.RequestOpt) (*discord.IncomingWebhook, error)

type ConfigOpt

type ConfigOpt func(config *config)

ConfigOpt is used to provide optional parameters to the webhook client

func WithDefaultAllowedMentions

func WithDefaultAllowedMentions(allowedMentions discord.AllowedMentions) ConfigOpt

WithDefaultAllowedMentions sets the default allowed mentions for the webhook client

func WithLogger

func WithLogger(logger *slog.Logger) ConfigOpt

WithLogger sets the logger for the webhook client

func WithRestClient

func WithRestClient(restClient rest.Client) ConfigOpt

WithRestClient sets the rest client for the webhook client

func WithRestClientConfigOpts

func WithRestClientConfigOpts(opts ...rest.ClientConfigOpt) ConfigOpt

WithRestClientConfigOpts sets the rest client configuration for the webhook client

func WithWebhooks

func WithWebhooks(webhooks rest.Webhooks) ConfigOpt

WithWebhooks sets the webhook service for the webhook client

Jump to

Keyboard shortcuts

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