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

discord: add URL method to Channel #439

Merged
merged 1 commit into from
Jul 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading