This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
PermissionGacha/modules/roles/check.go

31 lines
610 B
Go

package roles
import (
"fmt"
"github.com/bwmarrin/discordgo"
"PermissionGacha/modules/config"
)
func GetOldLevel(s *discordgo.Session, id string) (int, error) {
member, err := s.GuildMember(config.GuildID, id)
if err != nil {
return 0, fmt.Errorf("roles: EligibleGachaCount: error fetching guild member (%s): %w", id, err)
}
var foundLevel = 0
levelSearchLoop:
for i := len(rolesFromLevel); i > 0; i-- {
for _, v := range member.Roles {
if rolesFromLevel[i-1] == v {
foundLevel = i
break levelSearchLoop
}
}
}
if foundLevel == 0 {
return 0, nil
}
return foundLevel, nil
}