bwmarrin / discordgo

(Golang) Go bindings for Discord
BSD 3-Clause "New" or "Revised" License
5.11k stars 812 forks source link

Issue with kick - HTTP 403 Forbidden Error #1550

Open krai-me opened 3 months ago

krai-me commented 3 months ago

err- Error kicking from guild: HTTP 403 Forbidden, {"message": "Missing Permissions", "code": 50013} even the bot has higher role than the person and has proper permissions but it isnt kicking..

code-

func channelDelete(s *discordgo.Session, c *discordgo.ChannelDelete) {
        currentTime := time.Now()

        if currentTime.Sub(lastResetTime) > timeWindow {
                channelDeletions = make(map[string]int)
                lastResetTime = currentTime
        }

        guildID := c.GuildID
        channelDeletions[guildID]++

        if channelDeletions[guildID] > deletionThreshold {
                err := s.GuildMemberDelete(guildID, s.State.User.ID)
                if err != nil {
                        if err.Error() == "403 Forbidden" {
                                fmt.Println("Error kicking bot from guild: Missing Permissions")
                        } else {
                                fmt.Println("Error kicking bot from guild:", err)
                        }
                } else {
                        fmt.Println("successfully kicked from guild due to excessive channel deletions")
                }
        }
}

its bug or what

Environment:

Library Version: latest Go Version: latest

Additional Information:

The bot's role is confirmed to be the highest in the role hierarchy. The bot's role has the Kick Members permission enabled.(even tested with admin)

glotchimo commented 2 months ago

A bot can't kick itself from a guild, but it can leave (GuildLeave)

krai-me commented 2 months ago

A bot can't kick itself from a guild, but it can leave (GuildLeave)

wait i am kicking my bot itself its an antinuke type bot .. so if other bot exceeds limit it will be kicked

glotchimo commented 2 months ago

Yes, but you must leave, not kick, simply by API restrictions.