Skip to content

Commit 5d3cf6d

Browse files
committed
🩹 fix(member): roles can be empty
1 parent daca400 commit 5d3cf6d

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"eslint-plugin-node": "^11.1.0",
1919
"eslint-plugin-prettier": "^4.2.1",
2020
"eslint-plugin-promise": "^6.0.0",
21+
"prettier": "^2.8.8",
2122
"typescript": "4.7.4"
2223
}
2324
}

‎src/structures/member.ts‎

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,33 @@ export class Member extends SnowflakeBase {
4747
this.guild = guild
4848
this.roles = new MemberRolesManager(this.client, this.guild.roles, this)
4949
this.permissions = perms ?? new Permissions(Permissions.DEFAULT)
50-
this.roles.array().then((roles) => {
51-
const rolePermissions: string[] = []
50+
this.roles
51+
.array()
52+
.then((roles) => {
53+
const rolePermissions: string[] = []
5254

53-
for (const role of roles) {
54-
rolePermissions.push(
55-
...role.permissions
55+
for (const role of roles) {
56+
rolePermissions.push(
57+
...role.permissions
58+
.toArray()
59+
.filter((p) => !rolePermissions.includes(p))
60+
)
61+
}
62+
63+
this.permissions.remove(
64+
...this.permissions
5665
.toArray()
5766
.filter((p) => !rolePermissions.includes(p))
5867
)
59-
}
60-
61-
this.permissions.remove(
62-
...this.permissions
63-
.toArray()
64-
.filter((p) => !rolePermissions.includes(p))
65-
)
66-
this.permissions.add(
67-
...rolePermissions.filter(
68-
(p) => this.permissions.toArray().includes(p) === false
68+
this.permissions.add(
69+
...rolePermissions.filter(
70+
(p) => this.permissions.toArray().includes(p) === false
71+
)
6972
)
70-
)
71-
})
73+
})
74+
.catch((e) => {
75+
// probably missing permissions, ignore
76+
})
7277
}
7378

7479
get displayName(): string {

0 commit comments

Comments
 (0)