1
0
mirror of https://github.com/Rapptz/discord.py.git synced 2025-05-09 23:39:50 +00:00

Update bot_has_permissions to use Interaction.app_permissions

This commit is contained in:
JohannesIBK 2022-07-05 03:47:47 +02:00 committed by GitHub
parent 37c7c8fb34
commit 65a270d35a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -343,7 +343,7 @@ def has_permissions(**perms: bool) -> Callable[[T], T]:
def bot_has_permissions(**perms: bool) -> Callable[[T], T]:
"""Similar to :func:`has_permissions` except checks if the bot itself has
the permissions listed.
the permissions listed. This relies on :attr:`discord.Interaction.app_permissions`.
This check raises a special exception, :exc:`~discord.app_commands.BotMissingPermissions`
that is inherited from :exc:`~discord.app_commands.CheckFailure`.
@ -356,13 +356,7 @@ def bot_has_permissions(**perms: bool) -> Callable[[T], T]:
raise TypeError(f"Invalid permission(s): {', '.join(invalid)}")
def predicate(interaction: Interaction) -> bool:
guild = interaction.guild
me = guild.me if guild is not None else interaction.client.user
if interaction.channel is None:
permissions = Permissions.none()
else:
permissions = interaction.channel.permissions_for(me) # type: ignore
permissions = interaction.app_permissions
missing = [perm for perm, value in perms.items() if getattr(permissions, perm) != value]
if not missing: