chenhg5/cc-connect · critical

discord: token is required

Error message

discord: token is required

What it means

The Discord platform constructor requires a bot token, read from the opts map under the key "token". If the option is absent or not a non-empty string, New returns this error instead of constructing a platform that could not authenticate. It is a fail-fast config validation at startup.

Source

Thrown at platform/discord/discord.go:83

	self                       core.Platform

	mu               sync.RWMutex
	session          *discordgo.Session
	cancel           context.CancelFunc
	stopping         bool
	everConnected    bool
	lifecycleHandler core.PlatformLifecycleHandler
}

const (
	discordInitialReconnectBackoff = 5 * time.Second
	discordMaxReconnectBackoff     = 5 * time.Minute
)

func New(opts map[string]any) (core.Platform, error) {
	token, _ := opts["token"].(string)
	if token == "" {
		return nil, fmt.Errorf("discord: token is required")
	}
	allowFrom, _ := opts["allow_from"].(string)
	core.CheckAllowFrom("discord", allowFrom)
	guildID, _ := opts["guild_id"].(string)
	var groupReplyAllGuilds []string
	if guilds, _ := opts["group_reply_all_guilds"].(string); guilds != "" {
		for _, g := range strings.Split(guilds, ",") {
			if g = strings.TrimSpace(g); g != "" {
				groupReplyAllGuilds = append(groupReplyAllGuilds, g)
			}
		}
	} else if all, _ := opts["group_reply_all"].(bool); all {
		groupReplyAllGuilds = []string{"*"}
	}
	shareSessionInChannel, _ := opts["share_session_in_channel"].(bool)
	threadIsolation, _ := opts["thread_isolation"].(bool)
	respondToAtEveryoneAndHere, _ := opts["respond_to_at_everyone_and_here"].(bool)
	// Default to "compact" so streaming edits work out of the box (Discord

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Add the bot token to config.toml: under the discord platform section set token = "your-bot-token".
  2. If the token comes from an env var, verify it is exported and non-empty before starting cc-connect.
  3. Ensure the value is a TOML string (wrap in quotes), not a number.
  4. Confirm the option key is exactly "token" (not "bot_token" or "discord_token").

Example fix

// before
[[platforms]]
name = "discord"
# token missing

// after
[[platforms]]
name = "discord"
token = "MTAw...bot-token..."
Defensive patterns

Strategy: validation

Validate before calling

cfg := os.Getenv("DISCORD_BOT_TOKEN")
if cfg == "" {
    log.Fatal("DISCORD_BOT_TOKEN is not set")
}

Type guard

func hasToken(opts map[string]any) bool {
    t, ok := opts["token"].(string)
    return ok && t != ""
}

Try / catch

p, err := discord.New(opts)
if err != nil && strings.Contains(err.Error(), "token is required") {
    log.Fatal("discord: missing token in config")
}

Prevention

When it happens

Trigger: Calling discord.New(opts) with opts missing the "token" key, with opts["token"] set to "" , or with a non-string value (e.g. a number read via TOML), so the type assertion opts["token"].(string) yields "".

Common situations: config.toml [platforms.discord] section missing the token field; token supplied via environment variable that is unset/empty; token value accidentally quoted as an integer or placed under the wrong platform name; typo like "bot_token" instead of "token".

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/2cf0784774169c4a. Report an issue: GitHub.