#Discord Webhook question
27 messages · Page 1 of 1 (latest)
the current var type im using is map[string]string
yes
Which doesn't allow you to nest json
ahh
I recommend you just make a short type for stuff and avoid map[string]any all together
It would be less error prone
expected operand, found '{'syntax
these are the kind of issues im getting
and wdym short type?
You're trying to write json where you should write go
values := map[string]any{
"embeds": []map[string]any{
{
"color": nil,
"fields": []map[string]any{
{
"name": "name",
"value": "value",
}
}
}
}
}
That should do it
thank you
That's super messy imo
Instead you can have struct definitions like this https://github.com/disgoorg/disgo/blob/master/discord/webhook_message_create.go
If you need this just once it doesn't matter too much I guess
use structs
type Webhook struct {
Content string `json:"content,omitempty"`
Username string `json:"username,omitempty"`
AvatarUrl string `json:"avatar_url,omitempty"`
Tts bool `json:"tts,omitempty"`
Embeds []Embed `json:"embeds,omitempty"`
}
type Embed struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Url string `json:"url,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
Color int `json:"color,omitempty"`
Footer EmbedFooter `json:"footer,omitempty"`
Image EmbedImage `json:"image,omitempty"`
Thumbnail EmbedThumbnail `json:"thumbnail,omitempty"`
Video EmbedVideo `json:"video,omitempty"`
Provider EmbedProvider `json:"provider,omitempty"`
Author EmbedAuthor `json:"author,omitempty"`
Fields []EmbedFields `json:"fields,omitempty"`
}
type EmbedFooter struct {
Text string `json:"text,omitempty"`
IconUrl string `json:"icon_url,omitempty"`
ProxyIconUrl string `json:"proxy_icon_url,omitempty"`
}
type EmbedImage struct {
Url string `json:"url,omitempty"`
ProxyUrl string `json:"proxy_url,omitempty"`
Height int `json:"height,omitempty"`
Width int `json:"width,omitempty"`
}
type EmbedThumbnail struct {
Url string `json:"url,omitempty"`
ProxyUrl string `json:"proxy_url,omitempty"`
Height int `json:"height,omitempty"`
Width int `json:"width,omitempty"`
}
type EmbedVideo struct {
Url string `json:"url,omitempty"`
ProxyUrl string `json:"proxy_url,omitempty"`
Height int `json:"height,omitempty"`
Width int `json:"width,omitempty"`
}
type EmbedProvider struct {
Name string `json:"name,omitempty"`
Url string `json:"url,omitempty"`
}
type EmbedAuthor struct {
Name string `json:"name,omitempty"`
Url string `json:"url,omitempty"`
IconUrl string `json:"icon_url,omitempty"`
ProxyIconUrl string `json:"proxy_icon_url,omitempty"`
}
type EmbedFields struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
Inline bool `json:"inline,omitempty"`
}
these r the discord webhook structs
I find this pretty confusing but thanks I'll have a look oh wait I kinda get it
I'll give it a go when I get home
it shouldn’t be confusing, what you do is just create a new webhook struct and fill the data, then JSON marshal it and send a post request to your webhook URL
it worked thank you