chenhg5/cc-connect · error

fetch guild roles: %w

Error message

fetch guild roles: %w

What it means

fetch guild roles wraps an error from discordgo's GuildRoles API call, used only when cached guild roles are not provided. The platform fetches the role list to locate the bot's highest role. It indicates the Discord REST call to list roles failed.

Source

Thrown at platform/discord/discord.go:1457

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)
		}
	}

	for _, role := range roles {
		if role == nil {
			continue
		}
		if _, ok := memberRoleSet[role.ID]; !ok {
			continue
		}
		if role.Managed {
			return role.ID, nil
		}
	}
	return "", nil
}

// classifyAttachments downloads and sorts Discord message attachments into

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Confirm guild ID correctness in config
  2. Ensure the bot is a member with at least view permissions in the guild
  3. Refresh the bot token
  4. Retry the operation; check for Discord API incidents
Defensive patterns

Strategy: retry

Validate before calling

if guildID == "" { return errors.New("guild ID is required") }

Try / catch

roles, err := s.GuildRoles(guildID)
if err != nil {
    if isRateLimit(err) { backoffAndRetry() }
    return fmt.Errorf("fetch guild roles: %w", err)
}

Prevention

When it happens

Trigger: resolveBotRoleIDForGuild (discord.go:1457) with empty guildRoles cache, and s.GuildRoles(guildID) fails due to bad guild ID, missing bot membership, expired token, network error, or rate limit.

Common situations: Bot lacks VIEWER/Server Insights access or was removed from the guild; misconfigured guild ID; token rotation mid-run; transient Discord 5xx.

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


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/73d90d4f683adc69. Report an issue: GitHub.