file description import type { Guild , Member } from "eris" ; import { Event } from "../classes/Event" ; export class AutoroleEvent extends Event { events = [ "guildMemberAdd" ] ; async run ( event , guild , member ) { if ( ! guild || ! member ) return ; const guildconfig = await this . bot . db . getGuildConfig ( guild ?. id ) ; if ( ! guildconfig ?. autoRoles ?. length ) return ; const mutecache = await this . bot . db . getGuildMuteCache ( guild . id ) ; const mutedMember = mutecache . find ( ( m ) => m . member === member . id ) ; if ( mutedMember && guildconfig . mutedRole ) return ; let cfgUpdated = false ; guildconfig . autoRoles . forEach ( ( role , i ) => { if ( ! guild . roles ?. has ( role ) ) { cfgUpdated = true ; return guildconfig . autoRoles . splice ( i , 1 ) ; } member . addRole ( role , "Role automatically given on join" ) . catch ( ( ) => { } ) ; } ) ; if ( cfgUpdated ) this . bot . db . updateGuildConfig ( guild . id , guildconfig ) ; } }