Skip to content

Parsing Options ​

Overview ​

Interaction option values arrive from Discord's JSON payload. InteractionContext provides typed accessors that preserve large snowflakes and safely handle absent values.

Quick Start ​

go
package main
import "github.com/discord-go/discord.go/bot"
func handle(c *bot.InteractionContext) { name := c.OptionString("name"); count := c.OptionInt("count"); target := c.OptionUser("target"); _ = c.Reply(name + " " + target.String() + " " + string(rune(count))) }

API Walkthrough ​

Use OptionString, OptionInt, OptionFloat, OptionBool, OptionUser, OptionRole, OptionChannel, Option, HasOption, Subcommand, and FocusedOption. Missing values return zero values; use HasOption when zero is meaningful. The previous Get* names (GetStringOption, GetIntOption, GetUserID, GetChannelID, and friends) still compile as deprecated aliases.

Common Mistakes ​

Do not decode Discord IDs through float64. JSON numbers can exceed JavaScript's safe integer range; the context uses json.Number internally.

Released under the Apache License 2.0.