Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
4
Indexable
Never
@bot.event
async def on_member_update(before, after):
    if before.guild.id == 884460833097273455 or before.guild.id == 1110605967596458036:
        before_roles = [role.name for role in before.roles]
        after_roles = [role.name for role in after.roles]
        
        if before_roles != after_roles:
            target_server_id = 1110605967596458036 if before.guild.id == 884460833097273455 else 884460833097273455 
            
            target_guild = bot.get_guild(target_server_id)
            
            roles_to_add = [role for role in after.roles if role.name not in before_roles]
            roles_to_remove = [role for role in before.roles if role.name not in after_roles]
            
            target_member = target_guild.get_member(after.id)
            
            for role in roles_to_add:
                target_role = discord.utils.get(target_guild.roles, name=role.name)
                await target_member.add_roles(target_role)
            
            for role in roles_to_remove:
                target_role = discord.utils.get(target_guild.roles, name=role.name)
                await target_member.remove_roles(target_role)