Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using discord's client, pasting an image URL as the only content for a message causes GuildID to be missing from the Message struct #1575

Open
azekeil opened this issue Sep 30, 2024 · 0 comments

Comments

@azekeil
Copy link

azekeil commented Sep 30, 2024

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"`
...
}
@azekeil azekeil changed the title Using discord's client, pasting an image URL as the only content for a message causes the GuildID to be missing from the Message struct Using discord's client, pasting an image URL as the only content for a message causes GuildID to be missing from the Message struct Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant