Channels/Chat
Discord
Post notifications to Discord channels via webhooks.
Discord webhooks are the fastest way to post into a Discord channel from external services. One URL per channel, no OAuth, no bot.
Setup
- In Discord, open the target channel's settings → Integrations → Webhooks → New Webhook.
- Name it, optionally set an avatar, pick a channel.
- Copy the Webhook URL.
import "github.com/gopackx/go-notification/channel/chat/discord"
notifier.RegisterChannel(discord.New(discord.Config{
Name: "discord",
WebhookURL: os.Getenv("DISCORD_WEBHOOK_URL"),
}))Sending
import "github.com/gopackx/go-notification/channel/chat"
func (n BuildFailed) Via(u notification.Notifiable) []string {
return []string{"discord"}
}
func (n BuildFailed) ToChat(u notification.Notifiable) *chat.Message {
return chat.NewMessage().
SetText("Build failed on " + n.Branch).
AddDiscordEmbed(chat.DiscordEmbed{
Title: n.Service,
Description: n.Error,
Color: 0xFF0000, // red
Fields: []chat.DiscordField{
{Name: "Commit", Value: n.Commit, Inline: true},
{Name: "Author", Value: n.Author, Inline: true},
},
})
}Configuration reference
| Field | Type | Required | Description |
|---|---|---|---|
WebhookURL | string | yes | Discord webhook URL (includes token — treat as a secret). |
DefaultUsername | string | no | Default bot name; override per message via DiscordUsername. |
Name | string | no | Channel name used by Via(). Defaults to "chat". |
Timeout | time.Duration | no | HTTP timeout per send. Default: 30s. |
Tips
- Rate limits — Discord caps webhook traffic at 30 requests per minute per webhook. Above that, requests get
429 Too Many Requests. Either throttle in-app, batch into fewer messages, or use multiple webhooks and round-robin. - Embed limits — 10 embeds per message, 6000 characters total across all embeds, 25 fields per embed. The builder won't stop you from exceeding these; Discord will reject.
- Secret in URL — rotate the webhook (delete + recreate) if you leak the URL.
Troubleshooting
401 Unauthorized— webhook was deleted or regenerated.400 Bad Request— usually a malformed embed (too many fields, too long, or invalid color). Error body includes which field.- Messages appear with wrong username/avatar — your
Usernameoverride may be blocked by server rules (rare).