Skip to content

Commit 02c82da

Browse files
ToothyDevNeloBlivionpre-commit-ci[bot]
authored
fix: 🐛 Add permission check to Role.is_assignable() (#3048)
Co-authored-by: Nelo <41271523+NeloBlivion@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 27e2592 commit 02c82da

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ These changes are available on the `master` branch, but have not yet been releas
1414

1515
### Changed
1616

17+
- Updated `Role.is_assignable()` to also check whether the bot has the `MANAGE_ROLES`
18+
permission. ([#3048](https://github.com/Pycord-Development/pycord/pull/3048))
19+
1720
### Fixed
1821

1922
- Fixed `RawMessageUpdateEvent.cached_message` being always `None` even when the message

discord/role.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,26 @@ def is_integration(self) -> bool:
443443
return self.tags is not None and self.tags.is_integration()
444444

445445
def is_assignable(self) -> bool:
446-
"""Whether the role is able to be assigned or removed by the bot.
446+
"""Whether the role is able to be assigned or removed by the bot. This checks whether all of the following conditions are true:
447+
448+
- The role is not the guild's :attr:`Guild.default_role`
449+
450+
- The role is not managed
451+
452+
- The bot has the :attr:`~Permissions.manage_roles` permission
453+
454+
- The bot's top role is above this role
447455
448456
.. versionadded:: 2.0
457+
.. versionchanged:: 2.7.1
458+
Added check for :attr:`~Permissions.manage_roles` permission
449459
"""
450460
me = self.guild.me
451461
return (
452462
not self.is_default()
453463
and not self.managed
454-
and (me.top_role > self or me.id == self.guild.owner_id)
464+
and me.guild_permissions.manage_roles
465+
and me.top_role > self
455466
)
456467

457468
def is_available_for_purchase(self) -> bool:

0 commit comments

Comments
 (0)