Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup member roles #18

Open
DaliborTrampota opened this issue May 15, 2022 · 2 comments
Open

Backup member roles #18

DaliborTrampota opened this issue May 15, 2022 · 2 comments

Comments

@DaliborTrampota
Copy link

It would be nice to have an option to backup member roles and restore them also an option to fetch members instead of taking them from cache

@DaliborTrampota
Copy link
Author

Okay I just found backupMembers option in the code as its not in the docs but it backups the role IDs and it never restores them. Role names have to be stored

function backupMemberRoles(members){
    return [...members.values()].map(m => ({
        id: m.id,
        roles: [...m.roles.cache.values()].map(r => r.name).filter(name => name != '@everyone')
    }))
}


async function restoreMemberRoles(members, backupRoles, gRoles){
    let promises = []
    for(let m of members){
        let roles = backupRoles.find(o => o.id == m.id)
        if(!roles) continue
        let roleIDs = gRoles.filter(r => roles.some(name => r.name == name)).map(r => r.id)
        promises.push(m.roles.add(roleIDs).then(o => true).catch(err => ({ id: m.id, roles, reason: err.message })))
    }
    return Promise.allSettled(promises)
}

@kntjspr
Copy link

kntjspr commented Jun 10, 2023

Okay I just found backupMembers option in the code as its not in the docs but it backups the role IDs and it never restores them. Role names have to be stored

function backupMemberRoles(members){
    return [...members.values()].map(m => ({
        id: m.id,
        roles: [...m.roles.cache.values()].map(r => r.name).filter(name => name != '@everyone')
    }))
}


async function restoreMemberRoles(members, backupRoles, gRoles){
    let promises = []
    for(let m of members){
        let roles = backupRoles.find(o => o.id == m.id)
        if(!roles) continue
        let roleIDs = gRoles.filter(r => roles.some(name => r.name == name)).map(r => r.id)
        promises.push(m.roles.add(roleIDs).then(o => true).catch(err => ({ id: m.id, roles, reason: err.message })))
    }
    return Promise.allSettled(promises)
}

Submit a pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants