chenhg5/cc-connect · error
fetch bot member: %w
Error message
fetch bot member: %w
What it means
fetch bot member wraps an error from discordgo's GuildMember call when resolving the bot's own member record (needed to compute its highest role) fails. Used to determine whether the bot can mention/interact with roles in a guild. The error is wrapped with context and returned to the caller.
Source
Thrown at platform/discord/discord.go:1442
func (p *Platform) cacheBotRoleIDForGuild(s *discordgo.Session, guildID string, guildRoles []*discordgo.Role) {
if s == nil || guildID == "" || p.botID == "" {
return
}
roleID, err := p.resolveBotRoleIDForGuild(s, guildID, guildRoles)
if err != nil {
slog.Debug("discord: resolve bot managed role failed", "guild", guildID, "error", err)
return
}
if roleID == "" {
return
}
p.botRoleIDs.Store(guildID, roleID)
}
func (p *Platform) resolveBotRoleIDForGuild(s *discordgo.Session, guildID string, guildRoles []*discordgo.Role) (string, error) {
member, err := s.GuildMember(guildID, p.botID)
if err != nil {
return "", fmt.Errorf("fetch bot member: %w", err)
}
if member == nil || len(member.Roles) == 0 {
return "", nil
}
memberRoleSet := make(map[string]struct{}, len(member.Roles))
for _, roleID := range member.Roles {
memberRoleSet[roleID] = struct{}{}
}
roles := guildRoles
if len(roles) == 0 {
roles, err = s.GuildRoles(guildID)
if err != nil {
return "", fmt.Errorf("fetch guild roles: %w", err)
}
}
View on GitHub (pinned to 4000b2338a)
Solutions
- Verify the bot is actually a member of the configured guild
- Check the guild ID in config.toml matches the target server
- Re-generate the bot token and restart
- Retry on 429/5xx; check Discord status page
Defensive patterns
Strategy: retry
Validate before calling
if p.botID == "" || guildID == "" { return errors.New("bot ID / guild ID required before resolving role") } Try / catch
member, err := s.GuildMember(guildID, p.botID)
if err != nil {
if shouldRetry(err) { time.Sleep(backoff); retry() }
return fmt.Errorf("fetch bot member: %w", err)
} Prevention
- Verify bot membership in guild during startup health checks
- Validate guild ID in config at boot
- Handle token rotation with re-auth hooks
When it happens
Trigger: Calling resolveBotRoleIDForGuild (discord.go:1442) when the bot token is invalid, the bot is not a member of the guild, the guildID is wrong, or the API is unreachable / rate limited.
Common situations: Bot kicked from the guild but config still references it; wrong guild ID in config.toml; expired or rotated bot token; Discord outage or 429.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- start thread for message %s: %w
- start thread in channel %s: %w
- discord: send fallback: %w
- discord: send: %w
- discord: send image fallback: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/f0836577d0a6aa82.
Report an issue: GitHub.