Skip to content

Commit

Permalink
🩹 fix(member): roles can be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Helloyunho committed May 30, 2023
1 parent daca400 commit 5d3cf6d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.0.0",
"prettier": "^2.8.8",
"typescript": "4.7.4"
}
}
39 changes: 22 additions & 17 deletions src/structures/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,33 @@ export class Member extends SnowflakeBase {
this.guild = guild
this.roles = new MemberRolesManager(this.client, this.guild.roles, this)
this.permissions = perms ?? new Permissions(Permissions.DEFAULT)
this.roles.array().then((roles) => {
const rolePermissions: string[] = []
this.roles
.array()
.then((roles) => {
const rolePermissions: string[] = []

for (const role of roles) {
rolePermissions.push(
...role.permissions
for (const role of roles) {
rolePermissions.push(
...role.permissions
.toArray()
.filter((p) => !rolePermissions.includes(p))
)
}

this.permissions.remove(
...this.permissions
.toArray()
.filter((p) => !rolePermissions.includes(p))
)
}

this.permissions.remove(
...this.permissions
.toArray()
.filter((p) => !rolePermissions.includes(p))
)
this.permissions.add(
...rolePermissions.filter(
(p) => this.permissions.toArray().includes(p) === false
this.permissions.add(
...rolePermissions.filter(
(p) => this.permissions.toArray().includes(p) === false
)
)
)
})
})
.catch((e) => {
// probably missing permissions, ignore
})
}

get displayName(): string {
Expand Down

0 comments on commit 5d3cf6d

Please sign in to comment.