{"record":{"id":"73d90d4f683adc69","repo":"chenhg5/cc-connect","slug":"fetch-guild-roles-w","errorCode":null,"errorMessage":"fetch guild roles: %w","messagePattern":"fetch guild roles: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/discord/discord.go","lineNumber":1457,"sourceCode":"func (p *Platform) resolveBotRoleIDForGuild(s *discordgo.Session, guildID string, guildRoles []*discordgo.Role) (string, error) {\n\tmember, err := s.GuildMember(guildID, p.botID)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"fetch bot member: %w\", err)\n\t}\n\tif member == nil || len(member.Roles) == 0 {\n\t\treturn \"\", nil\n\t}\n\n\tmemberRoleSet := make(map[string]struct{}, len(member.Roles))\n\tfor _, roleID := range member.Roles {\n\t\tmemberRoleSet[roleID] = struct{}{}\n\t}\n\n\troles := guildRoles\n\tif len(roles) == 0 {\n\t\troles, err = s.GuildRoles(guildID)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"fetch guild roles: %w\", err)\n\t\t}\n\t}\n\n\tfor _, role := range roles {\n\t\tif role == nil {\n\t\t\tcontinue\n\t\t}\n\t\tif _, ok := memberRoleSet[role.ID]; !ok {\n\t\t\tcontinue\n\t\t}\n\t\tif role.Managed {\n\t\t\treturn role.ID, nil\n\t\t}\n\t}\n\treturn \"\", nil\n}\n\n// classifyAttachments downloads and sorts Discord message attachments into","sourceCodeStart":1439,"sourceCodeEnd":1475,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/discord/discord.go#L1439-L1475","documentation":"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.","triggerScenarios":"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.","commonSituations":"Bot lacks VIEWER/Server Insights access or was removed from the guild; misconfigured guild ID; token rotation mid-run; transient Discord 5xx.","solutions":["Confirm guild ID correctness in config","Ensure the bot is a member with at least view permissions in the guild","Refresh the bot token","Retry the operation; check for Discord API incidents"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if guildID == \"\" { return errors.New(\"guild ID is required\") }","typeGuard":null,"tryCatchPattern":"roles, err := s.GuildRoles(guildID)\nif err != nil {\n    if isRateLimit(err) { backoffAndRetry() }\n    return fmt.Errorf(\"fetch guild roles: %w\", err)\n}","preventionTips":["Prefer passing cached guildRoles to avoid the extra API call","Check bot guild membership and token before role resolution","Monitor Discord API status; degrade gracefully when roles can't be resolved"],"tags":["discord","api","roles"],"backgroundTag":"api-request-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}