Skip to content

Commit e94e7e0

Browse files
committed
addRole and removeRole permission checks
1 parent 28b2c50 commit e94e7e0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Discord/Parts/User/Member.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ public function addRole($role, ?string $reason = null): PromiseInterface
303303
return reject(new NoPermissionsException("You do not have permission to add member role in the guild {$guild->id}."));
304304
}
305305
}
306+
if ($botHighestRole = $guild->roles->getCurrentMemberHighestRole()) {
307+
if ($botHighestRole->comparePosition($this) <= 0) {
308+
return reject(new NoPermissionsException("The bot's highest role is not higher than the role {$this->id} in guild {$this->guild_id}."));
309+
}
310+
}
306311
}
307312

308313
$headers = [];
@@ -342,6 +347,11 @@ public function removeRole($role, ?string $reason = null): PromiseInterface
342347
return reject(new NoPermissionsException("You do not have permission to remove member role in the guild {$guild->id}."));
343348
}
344349
}
350+
if ($botHighestRole = $guild->roles->getCurrentMemberHighestRole()) {
351+
if ($botHighestRole->comparePosition($this) <= 0) {
352+
return reject(new NoPermissionsException("The bot's highest role is not higher than the role {$this->id} in guild {$this->guild_id}."));
353+
}
354+
}
345355
}
346356

347357
$headers = [];

0 commit comments

Comments
 (0)