Skip to content

Commit

Permalink
discord: add URL method to Channel
Browse files Browse the repository at this point in the history
  • Loading branch information
samhza authored and diamondburned committed Jul 14, 2024
1 parent 5d7b2e3 commit 0ec9fe5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions discord/channel.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package discord

import (
"fmt"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -161,6 +162,20 @@ func (ch Channel) Mention() string {
return ch.ID.Mention()
}

// URL generates a Discord client URL to the channel. If the channel doesn't
// have a GuildID, it will generate a URL with the guild "@me".
func (c Channel) URL() string {
var guildID = "@me"
if c.GuildID.IsValid() {
guildID = c.GuildID.String()
}

return fmt.Sprintf(
"https://discord.com/channels/%s/%s",
guildID, c.ID.String(),
)
}

// IconURL returns the URL to the channel icon in the PNG format.
// An empty string is returned if there's no icon.
func (ch Channel) IconURL() string {
Expand Down

0 comments on commit 0ec9fe5

Please sign in to comment.