Skip to content

Commit

Permalink
override stringvalue of option
Browse files Browse the repository at this point in the history
  • Loading branch information
zekroTJA committed Oct 9, 2021
1 parent 8bbe671 commit 298391b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ken

import (
"strings"

"github.com/bwmarrin/discordgo"
)

Expand Down Expand Up @@ -117,3 +119,13 @@ func (o *CommandOption) UserValue(ctx *Ctx) *discordgo.User {

return user
}

// StringValue is a utility function for casting option value to string.
//
// Because you can not pass multiline string entries to slash commands,
// this converts `\n` in a message to an actual line break.
func (o *CommandOption) StringValue() (v string) {
v = o.ApplicationCommandInteractionDataOption.StringValue()
v = strings.ReplaceAll(v, "\\n", "\n")
return
}

0 comments on commit 298391b

Please sign in to comment.