mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-19 15:36:02 +00:00
Add on_raw_app_command_permissions_update event
This commit is contained in:
parent
55b9a848ff
commit
1aaa32d4bc
@ -29,6 +29,7 @@ from typing import TYPE_CHECKING, Optional, Set, List, Tuple, Union
|
||||
|
||||
from .enums import ChannelType, try_enum
|
||||
from .utils import _get_as_snowflake
|
||||
from .app_commands import AppCommandPermissions
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .types.gateway import (
|
||||
@ -46,11 +47,14 @@ if TYPE_CHECKING:
|
||||
TypingStartEvent,
|
||||
GuildMemberRemoveEvent,
|
||||
)
|
||||
from .types.command import GuildApplicationCommandPermissions
|
||||
from .message import Message
|
||||
from .partial_emoji import PartialEmoji
|
||||
from .member import Member
|
||||
from .threads import Thread
|
||||
from .user import User
|
||||
from .state import ConnectionState
|
||||
from .guild import Guild
|
||||
|
||||
ReactionActionEvent = Union[MessageReactionAddEvent, MessageReactionRemoveEvent]
|
||||
|
||||
@ -68,6 +72,7 @@ __all__ = (
|
||||
'RawThreadMembersUpdate',
|
||||
'RawTypingEvent',
|
||||
'RawMemberRemoveEvent',
|
||||
'RawAppCommandPermissionsUpdateEvent',
|
||||
)
|
||||
|
||||
|
||||
@ -432,3 +437,33 @@ class RawMemberRemoveEvent(_RawReprMixin):
|
||||
def __init__(self, data: GuildMemberRemoveEvent, user: User, /) -> None:
|
||||
self.user: Union[User, Member] = user
|
||||
self.guild_id: int = int(data['guild_id'])
|
||||
|
||||
|
||||
class RawAppCommandPermissionsUpdateEvent(_RawReprMixin):
|
||||
"""Represents the payload for a :func:`on_raw_app_command_permissions_update` event.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
Attributes
|
||||
----------
|
||||
target_id: :class:`int`
|
||||
The ID of the command or application whos permissions were updated.
|
||||
When this is the application ID instead of a command ID, the permissions
|
||||
apply to all commands that do not contain explicit overwrites.
|
||||
application_id: :class:`int`
|
||||
The ID of the application that the command belongs to.
|
||||
guild: :class:`~discord.Guild`
|
||||
The guild where the permissions were updated.
|
||||
permissions: List[:class:`~discord.app_commands.AppCommandPermissions`]
|
||||
List of new permissions for the app command.
|
||||
"""
|
||||
|
||||
__slots__ = ('target_id', 'application_id', 'guild', 'permissions')
|
||||
|
||||
def __init__(self, *, data: GuildApplicationCommandPermissions, state: ConnectionState):
|
||||
self.target_id: int = int(data['id'])
|
||||
self.application_id: int = int(data['application_id'])
|
||||
self.guild: Guild = state._get_or_create_unavailable_guild(int(data['guild_id']))
|
||||
self.permissions: List[AppCommandPermissions] = [
|
||||
AppCommandPermissions(data=perm, guild=self.guild, state=state) for perm in data['permissions']
|
||||
]
|
||||
|
@ -95,6 +95,7 @@ if TYPE_CHECKING:
|
||||
from .types.guild import Guild as GuildPayload
|
||||
from .types.message import Message as MessagePayload, PartialMessage as PartialMessagePayload
|
||||
from .types import gateway as gw
|
||||
from .types.command import GuildApplicationCommandPermissions as GuildApplicationCommandPermissionsPayload
|
||||
|
||||
T = TypeVar('T')
|
||||
Channel = Union[GuildChannel, VocalGuildChannel, PrivateChannel, PartialMessageable]
|
||||
@ -1475,6 +1476,10 @@ class ConnectionState:
|
||||
else:
|
||||
_log.debug('SCHEDULED_EVENT_USER_REMOVE referencing unknown guild ID: %s. Discarding.', data['guild_id'])
|
||||
|
||||
def parse_application_command_permissions_update(self, data: GuildApplicationCommandPermissionsPayload):
|
||||
raw = RawAppCommandPermissionsUpdateEvent(data=data, state=self)
|
||||
self.dispatch('raw_app_command_permissions_update', raw)
|
||||
|
||||
def parse_voice_state_update(self, data: gw.VoiceStateUpdateEvent) -> None:
|
||||
guild = self._get_guild(utils._get_as_snowflake(data, 'guild_id'))
|
||||
channel_id = utils._get_as_snowflake(data, 'channel_id')
|
||||
|
22
docs/api.rst
22
docs/api.rst
@ -203,8 +203,20 @@ to handle it, which defaults to logging the traceback and ignoring the exception
|
||||
errors. In order to turn a function into a coroutine they must be ``async def``
|
||||
functions.
|
||||
|
||||
App Commands
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
.. function:: on_raw_app_command_permissions_update(payload)
|
||||
|
||||
Called when application command permissions are updated.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
:param payload: The raw event payload data.
|
||||
:type payload: :class:`RawAppCommandPermissionsUpdateEvent`
|
||||
|
||||
AutoMod
|
||||
~~~~~~~
|
||||
~~~~~~~~
|
||||
|
||||
.. function:: on_automod_rule_create(rule)
|
||||
|
||||
@ -4417,6 +4429,14 @@ RawMemberRemoveEvent
|
||||
.. autoclass:: RawMemberRemoveEvent()
|
||||
:members:
|
||||
|
||||
RawAppCommandPermissionsUpdateEvent
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. attributetable:: RawAppCommandPermissionsUpdateEvent
|
||||
|
||||
.. autoclass:: RawAppCommandPermissionsUpdateEvent()
|
||||
:members:
|
||||
|
||||
PartialWebhookGuild
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user