#Discord Webhook question

27 messages · Page 1 of 1 (latest)

raw cargo
#

To support such nested json you need to use a map[string]any

lavish gust
#

the current var type im using is map[string]string

raw cargo
#

yes
Which doesn't allow you to nest json

lavish gust
#

ahh

raw cargo
#

I recommend you just make a short type for stuff and avoid map[string]any all together

#

It would be less error prone

lavish gust
#

expected operand, found '{'syntax

#

these are the kind of issues im getting

#

and wdym short type?

raw cargo
#

You're trying to write json where you should write go

lavish gust
#

yes im just unsure what go i should be writing

#

in place

raw cargo
#
values := map[string]any{
  "embeds": []map[string]any{
    {
      "color": nil,
      "fields": []map[string]any{
        {
          "name": "name",
          "value": "value",
         }
      }
     }
  }
}
#

That should do it

lavish gust
#

thank you

raw cargo
#

That's super messy imo

lavish gust
#

as long as it gets it done tbh

#

i understand what im doing wrong now lol cheers

raw cargo
#

If you need this just once it doesn't matter too much I guess

vital sluice
#

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

lavish gust
#

I'll give it a go when I get home

vital sluice
#

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