diff --git a/discord/application_command.go b/discord/application_command.go index 46835719..93a7d536 100644 --- a/discord/application_command.go +++ b/discord/application_command.go @@ -180,6 +180,10 @@ func (c SlashCommand) CreatedAt() time.Time { return c.id.Time() } +func (c SlashCommand) Mention() string { + return SlashCommandMention(c.id, c.name) +} + func (SlashCommand) applicationCommand() {} var _ ApplicationCommand = (*UserCommand)(nil) diff --git a/discord/mentionable.go b/discord/mentionable.go index 79b27a15..37b22279 100644 --- a/discord/mentionable.go +++ b/discord/mentionable.go @@ -12,13 +12,14 @@ type MentionType struct { } var ( - MentionTypeUser = MentionType{regexp.MustCompile(`<@!?(\d+)>`)} - MentionTypeRole = MentionType{regexp.MustCompile(`<@&(\d+)>`)} - MentionTypeChannel = MentionType{regexp.MustCompile(`<#(\d+)>`)} - MentionTypeEmoji = MentionType{regexp.MustCompile(``)} - MentionTypeTimestamp = MentionType{regexp.MustCompile(`-?\d{1,17})(?::(?P[tTdDfFR]))?>`)} - MentionTypeHere = MentionType{regexp.MustCompile(`@here`)} - MentionTypeEveryone = MentionType{regexp.MustCompile(`@everyone`)} + MentionTypeUser = MentionType{regexp.MustCompile(`<@!?(\d+)>`)} + MentionTypeRole = MentionType{regexp.MustCompile(`<@&(\d+)>`)} + MentionTypeChannel = MentionType{regexp.MustCompile(`<#(\d+)>`)} + MentionTypeEmoji = MentionType{regexp.MustCompile(``)} + MentionTypeTimestamp = MentionType{regexp.MustCompile(`-?\d{1,17})(?::(?P[tTdDfFR]))?>`)} + MentionTypeSlashCommand = MentionType{regexp.MustCompile(``)} + MentionTypeHere = MentionType{regexp.MustCompile(`@here`)} + MentionTypeEveryone = MentionType{regexp.MustCompile(`@everyone`)} ) type Mentionable interface { @@ -57,3 +58,11 @@ func TimestampMention(timestamp int64) string { func FormattedTimestampMention(timestamp int64, style TimestampStyle) string { return fmt.Sprintf("", timestamp, style) } + +// SlashCommandMention creates a slash command mention. +// You can also pass a subcommand (and/or a subcommand group respectively) to the path. +// +// mention := SlashCommandMention(id, "command group subcommand") +func SlashCommandMention(id snowflake.ID, path string) string { + return fmt.Sprintf("", path, id) +}