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

  1. Set a valid bot token from the Discord Developer Portal (Bot -> Reset Token) in the discord channel config
  2. If the token is env-sourced, confirm the variable is set in the runtime environment and restart
  3. 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

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


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/398fbd3dfe5bf4f9. Report an issue: GitHub.