{"record":{"id":"398fbd3dfe5bf4f9","repo":"sipeed/picoclaw","slug":"failed-to-create-discord-session-w","errorCode":null,"errorMessage":"failed to create discord session: %w","messagePattern":"failed to create discord session: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/channels/discord/discord.go","lineNumber":79,"sourceCode":"\tttsPlayID uint64\n}\n\nfunc NewDiscordChannel(\n\tbc *config.Channel,\n\tcfg *config.DiscordSettings,\n\tbus *bus.MessageBus,\n) (*DiscordChannel, error) {\n\tdiscordgo.Logger = logger.NewLogger(\"discord\").\n\t\tWithLevels(map[int]logger.LogLevel{\n\t\t\tdiscordgo.LogError:         logger.ERROR,\n\t\t\tdiscordgo.LogWarning:       logger.WARN,\n\t\t\tdiscordgo.LogInformational: logger.INFO,\n\t\t\tdiscordgo.LogDebug:         logger.DEBUG,\n\t\t}).Log\n\n\tsession, err := discordgo.New(\"Bot \" + cfg.Token.String())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create discord session: %w\", err)\n\t}\n\n\tif err := applyDiscordProxy(session, cfg.Proxy); err != nil {\n\t\treturn nil, err\n\t}\n\tbase := channels.NewBaseChannel(\"discord\", cfg, bus, bc.AllowFrom,\n\t\tchannels.WithMaxMessageLength(2000),\n\t\tchannels.WithGroupTrigger(bc.GroupTrigger),\n\t\tchannels.WithReasoningChannelID(bc.ReasoningChannelID),\n\t)\n\n\tch := &DiscordChannel{\n\t\tBaseChannel: base,\n\t\tbc:          bc,\n\t\tsession:     session,\n\t\tconfig:      cfg,\n\t\tctx:         context.Background(),\n\t\ttypingStop:  make(map[string]chan struct{}),","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/channels/discord/discord.go#L61-L97","documentation":"discordgo.New(\"Bot \"+token) failed during channel construction. discordgo.New essentially only errors on a blank/invalid authentication argument, so in practice this means the Discord bot token is empty — the channel never gets created.","triggerScenarios":"NewDiscordChannel called with an empty token in DiscordSettings: token key missing from config, empty string, or an env-var reference that resolves to empty.","commonSituations":"Fresh setup without setting discord.token in config, token env var not exported in docker/systemd, YAML key typo or wrong indentation, secret redacted in deployed config.","solutions":["Set a valid bot token from the Discord Developer Portal (Bot -> Reset Token) in the discord channel config","If the token is env-sourced, confirm the variable is set in the runtime environment and restart","Verify the token loads: log len(cfg.Token.String()) at startup (length only, never the value)"],"exampleFix":"# before\nchannels:\n  discord:\n    enabled: true\n\n# after\nchannels:\n  discord:\n    enabled: true\n    token: \"MTIzNDU2Nzg5.GABCDEF...\"","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(cfg.Token.String()) == \"\" {\n    return nil, fmt.Errorf(\"discord token is required\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set discord.token from the Developer Portal before enabling the channel","If env-sourced, verify the variable is present in the service environment at deploy time","Fail fast at config load: an empty token should abort startup with a clear message, not reach discordgo.New"],"tags":["discord","config","token","startup"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}