Skip to content

Commit 51d8845

Browse files
authored
feat: allow by?: Member in Member#{manageable, kickable, bannable}
1 parent 029af49 commit 51d8845

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/structures/member.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,31 +205,31 @@ export class Member extends SnowflakeBase {
205205
return this.guild.bans.add(this.id, reason, deleteOldMessages)
206206
}
207207

208-
async manageable(): Promise<boolean> {
209-
if (this.id === this.guild.ownerID || this.id === this.client.user?.id)
208+
async manageable(by?: Member): Promise<boolean> {
209+
by = by ?? await this.guild.me()
210+
if (this.id === this.guild.ownerID || this.id === by.id)
210211
return false
211-
if (this.guild.ownerID === this.client.user?.id) return true
212-
const me = await this.guild.me()
213-
const highestMe = (await me.roles.array()).sort(
212+
if (this.guild.ownerID === by.id) return true
213+
const highestBy = (await by.roles.array()).sort(
214214
(b, a) => a.position - b.position
215215
)[0]
216216
const highest = (await this.roles.array()).sort(
217217
(b, a) => a.position - b.position
218218
)[0]
219-
return highestMe.position > highest.position
219+
return highestBy.position > highest.position
220220
}
221221

222-
async bannable(): Promise<boolean> {
223-
const manageable = await this.manageable()
222+
async bannable(by?: Member): Promise<boolean> {
223+
const manageable = await this.manageable(by)
224224
if (!manageable) return false
225-
const me = await this.guild.me()
225+
const me = by ?? await this.guild.me()
226226
return me.permissions.has('BAN_MEMBERS')
227227
}
228228

229-
async kickable(): Promise<boolean> {
230-
const manageable = await this.manageable()
229+
async kickable(by?: Member): Promise<boolean> {
230+
const manageable = await this.manageable(by)
231231
if (!manageable) return false
232-
const me = await this.guild.me()
232+
const me = by ?? await this.guild.me()
233233
return me.permissions.has('KICK_MEMBERS')
234234
}
235235
}

0 commit comments

Comments
 (0)