mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-05 09:26:10 +00:00
First pass at supporting user apps
Co-authored-by: red <red@kalab.sk> Co-authored-by: Vioshim <63890837+Vioshim@users.noreply.github.com>
This commit is contained in:
@ -26,9 +26,17 @@ from __future__ import annotations
|
||||
from datetime import datetime
|
||||
|
||||
from .errors import MissingApplicationID
|
||||
from ..flags import AppCommandContext, AppInstallationType
|
||||
from .translator import TranslationContextLocation, TranslationContext, locale_str, Translator
|
||||
from ..permissions import Permissions
|
||||
from ..enums import AppCommandOptionType, AppCommandType, AppCommandPermissionType, ChannelType, Locale, try_enum
|
||||
from ..enums import (
|
||||
AppCommandOptionType,
|
||||
AppCommandType,
|
||||
AppCommandPermissionType,
|
||||
ChannelType,
|
||||
Locale,
|
||||
try_enum,
|
||||
)
|
||||
from ..mixins import Hashable
|
||||
from ..utils import _get_as_snowflake, parse_time, snowflake_time, MISSING
|
||||
from ..object import Object
|
||||
@ -160,6 +168,14 @@ class AppCommand(Hashable):
|
||||
The default member permissions that can run this command.
|
||||
dm_permission: :class:`bool`
|
||||
A boolean that indicates whether this command can be run in direct messages.
|
||||
allowed_contexts: Optional[:class:`~discord.app_commands.AppCommandContext`]
|
||||
The contexts that this command is allowed to be used in. Overrides the ``dm_permission`` attribute.
|
||||
|
||||
.. versionadded:: 2.4
|
||||
allowed_installs: Optional[:class:`~discord.app_commands.AppInstallationType`]
|
||||
The installation contexts that this command is allowed to be installed in.
|
||||
|
||||
.. versionadded:: 2.4
|
||||
guild_id: Optional[:class:`int`]
|
||||
The ID of the guild this command is registered in. A value of ``None``
|
||||
denotes that it is a global command.
|
||||
@ -179,6 +195,8 @@ class AppCommand(Hashable):
|
||||
'options',
|
||||
'default_member_permissions',
|
||||
'dm_permission',
|
||||
'allowed_contexts',
|
||||
'allowed_installs',
|
||||
'nsfw',
|
||||
'_state',
|
||||
)
|
||||
@ -210,6 +228,19 @@ class AppCommand(Hashable):
|
||||
dm_permission = True
|
||||
|
||||
self.dm_permission: bool = dm_permission
|
||||
|
||||
allowed_contexts = data.get('contexts')
|
||||
if allowed_contexts is None:
|
||||
self.allowed_contexts: Optional[AppCommandContext] = None
|
||||
else:
|
||||
self.allowed_contexts = AppCommandContext._from_value(allowed_contexts)
|
||||
|
||||
allowed_installs = data.get('integration_types')
|
||||
if allowed_installs is None:
|
||||
self.allowed_installs: Optional[AppInstallationType] = None
|
||||
else:
|
||||
self.allowed_installs = AppInstallationType._from_value(allowed_installs)
|
||||
|
||||
self.nsfw: bool = data.get('nsfw', False)
|
||||
self.name_localizations: Dict[Locale, str] = _to_locale_dict(data.get('name_localizations') or {})
|
||||
self.description_localizations: Dict[Locale, str] = _to_locale_dict(data.get('description_localizations') or {})
|
||||
@ -223,6 +254,8 @@ class AppCommand(Hashable):
|
||||
'description': self.description,
|
||||
'name_localizations': {str(k): v for k, v in self.name_localizations.items()},
|
||||
'description_localizations': {str(k): v for k, v in self.description_localizations.items()},
|
||||
'contexts': self.allowed_contexts.to_array() if self.allowed_contexts is not None else None,
|
||||
'integration_types': self.allowed_installs.to_array() if self.allowed_installs is not None else None,
|
||||
'options': [opt.to_dict() for opt in self.options],
|
||||
} # type: ignore # Type checker does not understand this literal.
|
||||
|
||||
|
Reference in New Issue
Block a user