mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-10-22 16:32:59 +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:
@@ -58,6 +58,7 @@ from .errors import (
|
||||
CommandSyncFailure,
|
||||
MissingApplicationID,
|
||||
)
|
||||
from .installs import AppCommandContext, AppInstallationType
|
||||
from .translator import Translator, locale_str
|
||||
from ..errors import ClientException, HTTPException
|
||||
from ..enums import AppCommandType, InteractionType
|
||||
@@ -121,9 +122,26 @@ class CommandTree(Generic[ClientT]):
|
||||
to find the guild-specific ``/ping`` command it will fall back to the global ``/ping`` command.
|
||||
This has the potential to raise more :exc:`~discord.app_commands.CommandSignatureMismatch` errors
|
||||
than usual. Defaults to ``True``.
|
||||
allowed_contexts: :class:`~discord.app_commands.AppCommandContext`
|
||||
The default allowed contexts that applies to all commands in this tree.
|
||||
Note that you can override this on a per command basis.
|
||||
|
||||
.. versionadded:: 2.4
|
||||
allowed_installs: :class:`~discord.app_commands.AppInstallationType`
|
||||
The default allowed install locations that apply to all commands in this tree.
|
||||
Note that you can override this on a per command basis.
|
||||
|
||||
.. versionadded:: 2.4
|
||||
"""
|
||||
|
||||
def __init__(self, client: ClientT, *, fallback_to_global: bool = True):
|
||||
def __init__(
|
||||
self,
|
||||
client: ClientT,
|
||||
*,
|
||||
fallback_to_global: bool = True,
|
||||
allowed_contexts: AppCommandContext = MISSING,
|
||||
allowed_installs: AppInstallationType = MISSING,
|
||||
):
|
||||
self.client: ClientT = client
|
||||
self._http = client.http
|
||||
self._state = client._connection
|
||||
@@ -133,6 +151,8 @@ class CommandTree(Generic[ClientT]):
|
||||
|
||||
self._state._command_tree = self
|
||||
self.fallback_to_global: bool = fallback_to_global
|
||||
self.allowed_contexts = AppCommandContext() if allowed_contexts is MISSING else allowed_contexts
|
||||
self.allowed_installs = AppInstallationType() if allowed_installs is MISSING else allowed_installs
|
||||
self._guild_commands: Dict[int, Dict[str, Union[Command, Group]]] = {}
|
||||
self._global_commands: Dict[str, Union[Command, Group]] = {}
|
||||
# (name, guild_id, command_type): Command
|
||||
@@ -722,7 +742,7 @@ class CommandTree(Generic[ClientT]):
|
||||
else:
|
||||
guild_id = None if guild is None else guild.id
|
||||
value = type.value
|
||||
for ((_, g, t), command) in self._context_menus.items():
|
||||
for (_, g, t), command in self._context_menus.items():
|
||||
if g == guild_id and t == value:
|
||||
yield command
|
||||
|
||||
@@ -1058,9 +1078,9 @@ class CommandTree(Generic[ClientT]):
|
||||
|
||||
translator = self.translator
|
||||
if translator:
|
||||
payload = [await command.get_translated_payload(translator) for command in commands]
|
||||
payload = [await command.get_translated_payload(self, translator) for command in commands]
|
||||
else:
|
||||
payload = [command.to_dict() for command in commands]
|
||||
payload = [command.to_dict(self) for command in commands]
|
||||
|
||||
try:
|
||||
if guild is None:
|
||||
|
Reference in New Issue
Block a user