sipeed/picoclaw · critical
failed to create discord session: %w
Error message
failed to create discord session: %w
What it means
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.
Source
Thrown at pkg/channels/discord/discord.go:79
ttsPlayID uint64
}
func NewDiscordChannel(
bc *config.Channel,
cfg *config.DiscordSettings,
bus *bus.MessageBus,
) (*DiscordChannel, error) {
discordgo.Logger = logger.NewLogger("discord").
WithLevels(map[int]logger.LogLevel{
discordgo.LogError: logger.ERROR,
discordgo.LogWarning: logger.WARN,
discordgo.LogInformational: logger.INFO,
discordgo.LogDebug: logger.DEBUG,
}).Log
session, err := discordgo.New("Bot " + cfg.Token.String())
if err != nil {
return nil, fmt.Errorf("failed to create discord session: %w", err)
}
if err := applyDiscordProxy(session, cfg.Proxy); err != nil {
return nil, err
}
base := channels.NewBaseChannel("discord", cfg, bus, bc.AllowFrom,
channels.WithMaxMessageLength(2000),
channels.WithGroupTrigger(bc.GroupTrigger),
channels.WithReasoningChannelID(bc.ReasoningChannelID),
)
ch := &DiscordChannel{
BaseChannel: base,
bc: bc,
session: session,
config: cfg,
ctx: context.Background(),
typingStop: make(map[string]chan struct{}),View on GitHub (pinned to 49183d7e8d)
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)
Example fix
# before
channels:
discord:
enabled: true
# after
channels:
discord:
enabled: true
token: "MTIzNDU2Nzg5.GABCDEF..." Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(cfg.Token.String()) == "" {
return nil, fmt.Errorf("discord token is required")
} Prevention
- 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
When it happens
Trigger: NewDiscordChannel called with an empty token in DiscordSettings: token key missing from config, empty string, or an env-var reference that resolves to empty.
Common situations: 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.
Related errors
- must be in range 1-65535
- failed to load MCP servers: %w
- failed to get bot user: %w
- failed to open discord session: %w
- invalid discord proxy URL %q: %w
AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15).
Data as JSON: /api/errors/398fbd3dfe5bf4f9.
Report an issue: GitHub.