sipeed/picoclaw · error
failed to get bot user: %w
Error message
failed to get bot user: %w
What it means
Start() calls session.User("@me") (GET /users/@me) before opening the gateway to capture botUserID and avoid a race. This error means that REST call failed: invalid/expired token (401), network or proxy failure reaching discord.com, or a Discord API error. The underlying discordgo error is wrapped with %w.
Source
Thrown at pkg/channels/discord/discord.go:115
typingStop: make(map[string]chan struct{}),
bus: bus,
voiceSSRC: make(map[string]map[uint32]string),
}
ch.playTTSFn = ch.playTTS
ch.ttsVoiceFn = ch.voiceConnectionForTTS
ch.progress = channels.NewToolFeedbackAnimator(ch.EditMessage)
return ch, nil
}
func (c *DiscordChannel) Start(ctx context.Context) error {
logger.InfoC("discord", "Starting Discord bot")
c.ctx, c.cancel = context.WithCancel(ctx)
// Get bot user ID before opening session to avoid race condition
botUser, err := c.session.User("@me")
if err != nil {
return fmt.Errorf("failed to get bot user: %w", err)
}
c.botUserID = botUser.ID
c.session.AddHandler(c.handleMessage)
go c.listenVoiceControl(c.ctx)
if err := c.session.Open(); err != nil {
return fmt.Errorf("failed to open discord session: %w", err)
}
c.SetRunning(true)
logger.InfoCF("discord", "Discord bot connected", map[string]any{
"username": botUser.Username,
"user_id": botUser.ID,
})
View on GitHub (pinned to 49183d7e8d)
Solutions
- Verify the token independently: curl -H 'Authorization: Bot <token>' https://discord.com/api/v10/users/@me should return 200 with the bot JSON
- Fix proxy configuration: valid scheme in discord.proxy (http/https/socks5) or unset broken HTTP_PROXY/HTTPS_PROXY
- Check network egress/DNS from the host and retry Start on transient failures
- If 401, create a new token in the Developer Portal and update config
Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight the token before Start()
req, _ := http.NewRequest(http.MethodGet, "https://discord.com/api/v10/users/@me", nil)
req.Header.Set("Authorization", "Bot "+cfg.Token.String())
resp, err := http.DefaultClient.Do(req)
if err != nil || resp.StatusCode != 200 {
return fmt.Errorf("discord token invalid or discord unreachable: %v / %d", err, respStatus(resp))
} Try / catch
if err := ch.Start(ctx); err != nil {
if strings.Contains(err.Error(), "failed to get bot user") {
// 401 => bad token (fix config); network error => fix egress/proxy, then retry
}
return err
} Prevention
- Validate the bot token with a users/@me REST call before starting the channel
- Keep proxy config valid — an unreachable HTTP(S)_PROXY breaks this REST call even with a good token
- When regenerating a token in the Developer Portal, update config immediately (old tokens are revoked)
- Retry Start with backoff only after excluding auth failure (401)
When it happens
Trigger: Token was regenerated in the Developer Portal (old token revoked), token typo/truncated, HTTP(S)_PROXY env or cfg.Proxy pointing to an unreachable proxy (applyDiscordProxy installs it on the session client), DNS/firewall blocking discord.com, Discord 5xx.
Common situations: Token reset in the portal but config not updated, container without network egress, proxy env vars leaking into the process, transient Discord API issues at startup.
Related errors
- failed to start stream client: %w
- failed to create discord session: %w
- failed to open discord session: %w
- invalid discord proxy URL %q: %w
- Invalid browser login response
AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15).
Data as JSON: /api/errors/bd8b535ca2a6b475.
Report an issue: GitHub.