add function to filter the role changes from member update

This commit is contained in:
mightypanders 2023-04-18 23:44:14 +02:00
parent 92d8f805b6
commit c28b37b0e9

View File

@ -0,0 +1,16 @@
import { GuildMember } from "discord.js"
import { ChangedRoles } from "../interfaces"
import { logger } from "../logger"
export function filterRolesFromMemberUpdate(oldMember: GuildMember, newMember: GuildMember): ChangedRoles {
const oldRoles = oldMember.roles.cache
const newRoles = newMember.roles.cache
const removedRoles = oldRoles.filter(x => newRoles.find(y => y.id === x.id) == undefined)
const addedRoles = newRoles.filter(x => oldRoles.find(y => y.id === x.id) == undefined)
logger.info(`Member ${oldMember.id} RemovedRoles: ${removedRoles.map(x => x.name)}`, { guildId: oldMember.guild.id })
logger.info(`Member ${oldMember.id} AddedRoles: ${addedRoles.map(x => x.name)}`, { guildId: oldMember.guild.id })
return { addedRoles, removedRoles }
}