github.com/diamondburned/arikawa/v2@v2.1.0/api/webhook.go (about) 1 package api 2 3 import ( 4 "github.com/diamondburned/arikawa/v2/discord" 5 "github.com/diamondburned/arikawa/v2/utils/httputil" 6 "github.com/diamondburned/arikawa/v2/utils/json/option" 7 ) 8 9 var EndpointWebhooks = Endpoint + "webhooks/" 10 11 // https://discord.com/developers/docs/resources/webhook#create-webhook-json-params 12 type CreateWebhookData struct { 13 // Name is the name of the webhook (1-80 characters). 14 Name string `json:"name"` 15 // Avatar is the image for the default webhook avatar. 16 Avatar *Image `json:"avatar"` 17 } 18 19 // CreateWebhook creates a new webhook. 20 // 21 // Webhooks cannot be named "clyde". 22 // 23 // Requires the MANAGE_WEBHOOKS permission. 24 func (c *Client) CreateWebhook( 25 channelID discord.ChannelID, data CreateWebhookData) (*discord.Webhook, error) { 26 27 var w *discord.Webhook 28 return w, c.RequestJSON( 29 &w, "POST", 30 EndpointChannels+channelID.String()+"/webhooks", 31 httputil.WithJSONBody(data), 32 ) 33 } 34 35 // ChannelWebhooks returns the webhooks of the channel with the given ID. 36 // 37 // Requires the MANAGE_WEBHOOKS permission. 38 func (c *Client) ChannelWebhooks(channelID discord.ChannelID) ([]discord.Webhook, error) { 39 var ws []discord.Webhook 40 return ws, c.RequestJSON(&ws, "GET", EndpointChannels+channelID.String()+"/webhooks") 41 } 42 43 // GuildWebhooks returns the webhooks of the guild with the given ID. 44 // 45 // Requires the MANAGE_WEBHOOKS permission. 46 func (c *Client) GuildWebhooks(guildID discord.GuildID) ([]discord.Webhook, error) { 47 var ws []discord.Webhook 48 return ws, c.RequestJSON(&ws, "GET", EndpointGuilds+guildID.String()+"/webhooks") 49 } 50 51 // Webhook returns the webhook with the given id. 52 func (c *Client) Webhook(webhookID discord.WebhookID) (*discord.Webhook, error) { 53 var w *discord.Webhook 54 return w, c.RequestJSON(&w, "GET", EndpointWebhooks+webhookID.String()) 55 } 56 57 // https://discord.com/developers/docs/resources/webhook#modify-webhook-json-params 58 type ModifyWebhookData struct { 59 // Name is the default name of the webhook. 60 Name option.String `json:"name,omitempty"` 61 // Avatar is the image for the default webhook avatar. 62 Avatar *Image `json:"avatar,omitempty"` 63 // ChannelID is the new channel id this webhook should be moved to. 64 ChannelID discord.ChannelID `json:"channel_id,omitempty"` 65 } 66 67 // ModifyWebhook modifies a webhook. 68 // 69 // Requires the MANAGE_WEBHOOKS permission. 70 func (c *Client) ModifyWebhook( 71 webhookID discord.WebhookID, data ModifyWebhookData) (*discord.Webhook, error) { 72 73 var w *discord.Webhook 74 return w, c.RequestJSON( 75 &w, "PATCH", 76 EndpointWebhooks+webhookID.String(), 77 httputil.WithJSONBody(data), 78 ) 79 } 80 81 // DeleteWebhook deletes a webhook permanently. 82 // 83 // Requires the MANAGE_WEBHOOKS permission. 84 func (c *Client) DeleteWebhook(webhookID discord.WebhookID) error { 85 return c.FastRequest("DELETE", EndpointWebhooks+webhookID.String()) 86 }