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

35 lines
786 B
Go

package roles
import (
"github.com/bwmarrin/discordgo"
"PermissionGacha/modules/config"
"PermissionGacha/modules/log"
)
func GiveLevelRoles(s *discordgo.Session, discordID string, oldLevel, newLevel int) error {
for i := oldLevel + 1; i <= newLevel; i++ {
err := s.GuildMemberRoleAdd(config.GuildID, discordID, config.LevelRoles[i-1])
if err != nil {
return err
}
}
return nil
}
func RemoveAllLevelRoles(s *discordgo.Session, discordID string) {
member, err := s.GuildMember(config.GuildID, discordID)
if err != nil {
log.Error(s, "RemoveAllLevelRoles", "GuildMember", discordID)
return
}
for _, v := range member.Roles {
for _, w := range config.LevelRoles {
if v == w {
s.GuildMemberRoleRemove(config.GuildID, discordID, v)
break
}
}
}
}