As per the title: If you paste a URL to an image as a message in the discord client, the client will re-render the URL as the image. My guess is this causes the discord client to not populate the GuildID field of the Message struct - I'm not sure if that's a problem on discord client end or discordgo library's end. I've worked around this in my code with the following:
func EnsureGuildID(s *discordgo.Session, m *discordgo.Message) {
if m.GuildID == "" {
c, err := s.Channel(m.ChannelID)
if err != nil {
log.Fatalf("unable to get GuildID from Channel: %v", err)
}
m.GuildID = c.GuildID
log.Printf("Added Guild %s to Message %s in Channel %s", m.GuildID, m.ID, m.ChannelID)
}
}
Other messages don't appear to cause this issue, just image URLs that have been converted to images. I imagine this is going to be tough to get fixed upstream; do we want to fix this in the library for now?
Is GuildID something we can rely on being set in the Message struct? I see that the struct tag implies it can be omitted if empty:
type Message struct {
...
// The ID of the guild in which the message was sent.
GuildID string `json:"guild_id,omitempty"`
...
}
As per the title: If you paste a URL to an image as a message in the discord client, the client will re-render the URL as the image. My guess is this causes the discord client to not populate the
GuildID
field of theMessage
struct - I'm not sure if that's a problem on discord client end or discordgo library's end. I've worked around this in my code with the following:Other messages don't appear to cause this issue, just image URLs that have been converted to images. I imagine this is going to be tough to get fixed upstream; do we want to fix this in the library for now?
Is GuildID something we can rely on being set in the Message struct? I see that the struct tag implies it can be omitted if empty: