From 4d547d6f1088185448e93794a904a3f8631cde11 Mon Sep 17 00:00:00 2001 From: "diamondburned (Forefront)" Date: Thu, 23 Jan 2020 21:49:34 -0800 Subject: [PATCH] Added Message URL method --- discord/message.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/discord/message.go b/discord/message.go index ce3a7f2..f736d78 100644 --- a/discord/message.go +++ b/discord/message.go @@ -52,6 +52,19 @@ type Message struct { Flags MessageFlags `json:"flags"` } +// URL generates a Discord client URL to the message. If the message doesn't +// have a GuildID, it will generate a URL with the guild "@me". +func (m Message) URL() string { + var head = "https://discordapp.com/channels/" + var tail = "/" + m.ChannelID.String() + "/" + m.ID.String() + + if !m.GuildID.Valid() { + return head + "@me" + tail + } + + return head + m.GuildID.String() + tail +} + type MessageType uint8 const (