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 (DiscordView on GitHub (pinned to 4000b2338a)
Solutions
- Add the bot token to config.toml: under the discord platform section set token = "your-bot-token".
- If the token comes from an env var, verify it is exported and non-empty before starting cc-connect.
- Ensure the value is a TOML string (wrap in quotes), not a number.
- 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
- Always set token as a quoted TOML string in the discord platform section
- Load secrets from environment with a startup check for emptiness
- Use exactly the key "token"; avoid alias key names
- Run cc-connect config validation/doctor before starting the daemon
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
- discord: invalid progress_style %q (want legacy, compact, or
- discord: invalid proxy URL %q: %w
- discord: create session: %w
- qqbot: failed to get access token: %w
- webex: getMe: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/2cf0784774169c4a.
Report an issue: GitHub.