Move MissingApplicationID to top-level discord namespace

This commit is contained in:
Rapptz 2024-08-31 08:51:56 -04:00
parent 66d74054dd
commit df4b1c88df
8 changed files with 39 additions and 26 deletions

View File

@ -84,4 +84,10 @@ version_info: VersionInfo = VersionInfo(major=2, minor=5, micro=0, releaselevel=
logging.getLogger(__name__).addHandler(logging.NullHandler())
# This is a backwards compatibility hack and should be removed in v3
# Essentially forcing the exception to have different base classes
# In the future, this should only inherit from ClientException
if len(MissingApplicationID.__bases__) == 1:
MissingApplicationID.__bases__ = (app_commands.AppCommandError, ClientException)
del logging, NamedTuple, Literal, VersionInfo

View File

@ -27,7 +27,7 @@ from __future__ import annotations
from typing import Any, TYPE_CHECKING, List, Optional, Sequence, Union
from ..enums import AppCommandOptionType, AppCommandType, Locale
from ..errors import DiscordException, HTTPException, _flatten_error_dict
from ..errors import DiscordException, HTTPException, _flatten_error_dict, MissingApplicationID as MissingApplicationID
from ..utils import _human_join
__all__ = (
@ -59,11 +59,6 @@ if TYPE_CHECKING:
CommandTypes = Union[Command[Any, ..., Any], Group, ContextMenu]
APP_ID_NOT_FOUND = (
'Client does not have an application_id set. Either the function was called before on_ready '
'was called or application_id was not passed to the Client constructor.'
)
class AppCommandError(DiscordException):
"""The base exception type for all application command related errors.
@ -422,19 +417,6 @@ class CommandSignatureMismatch(AppCommandError):
super().__init__(msg)
class MissingApplicationID(AppCommandError):
"""An exception raised when the client does not have an application ID set.
An application ID is required for syncing application commands.
This inherits from :exc:`~discord.app_commands.AppCommandError`.
.. versionadded:: 2.0
"""
def __init__(self, message: Optional[str] = None):
super().__init__(message or APP_ID_NOT_FOUND)
def _get_command_error(
index: str,
inner: Any,

View File

@ -84,7 +84,7 @@ if TYPE_CHECKING:
from typing_extensions import Self
from .abc import Messageable, PrivateChannel, Snowflake, SnowflakeTime
from .app_commands import Command, ContextMenu, MissingApplicationID
from .app_commands import Command, ContextMenu
from .automod import AutoModAction, AutoModRule
from .channel import DMChannel, GroupChannel
from .ext.commands import AutoShardedBot, Bot, Context, CommandError

View File

@ -29,7 +29,7 @@ from .asset import Asset, AssetMixin
from .utils import SnowflakeList, snowflake_time, MISSING
from .partial_emoji import _EmojiTag, PartialEmoji
from .user import User
from .app_commands.errors import MissingApplicationID
from .errors import MissingApplicationID
from .object import Object
# fmt: off

View File

@ -47,6 +47,12 @@ __all__ = (
'ConnectionClosed',
'PrivilegedIntentsRequired',
'InteractionResponded',
'MissingApplicationID',
)
APP_ID_NOT_FOUND = (
'Client does not have an application_id set. Either the function was called before on_ready '
'was called or application_id was not passed to the Client constructor.'
)
@ -278,3 +284,22 @@ class InteractionResponded(ClientException):
def __init__(self, interaction: Interaction):
self.interaction: Interaction = interaction
super().__init__('This interaction has already been responded to before')
class MissingApplicationID(ClientException):
"""An exception raised when the client does not have an application ID set.
An application ID is required for syncing application commands and various
other application tasks such as SKUs or application emojis.
This inherits from :exc:`~discord.app_commands.AppCommandError`
and :class:`~discord.ClientException`.
.. versionadded:: 2.0
.. versionchanged:: 2.5
This is now exported to the ``discord`` namespace and now inherits from :class:`~discord.ClientException`.
"""
def __init__(self, message: Optional[str] = None):
super().__init__(message or APP_ID_NOT_FOUND)

View File

@ -28,7 +28,7 @@ from __future__ import annotations
from typing import Optional, TYPE_CHECKING
from . import utils
from .app_commands import MissingApplicationID
from .errors import MissingApplicationID
from .enums import try_enum, SKUType, EntitlementType
from .flags import SKUFlags

View File

@ -5440,6 +5440,8 @@ The following exceptions are thrown by the library.
.. autoexception:: InteractionResponded
.. autoexception:: MissingApplicationID
.. autoexception:: discord.opus.OpusError
.. autoexception:: discord.opus.OpusNotLoaded
@ -5457,6 +5459,7 @@ Exception Hierarchy
- :exc:`ConnectionClosed`
- :exc:`PrivilegedIntentsRequired`
- :exc:`InteractionResponded`
- :exc:`MissingApplicationID`
- :exc:`GatewayNotFound`
- :exc:`HTTPException`
- :exc:`Forbidden`

View File

@ -872,9 +872,6 @@ Exceptions
.. autoexception:: discord.app_commands.CommandNotFound
:members:
.. autoexception:: discord.app_commands.MissingApplicationID
:members:
.. autoexception:: discord.app_commands.CommandSyncFailure
:members:
@ -899,7 +896,7 @@ Exception Hierarchy
- :exc:`~discord.app_commands.CommandAlreadyRegistered`
- :exc:`~discord.app_commands.CommandSignatureMismatch`
- :exc:`~discord.app_commands.CommandNotFound`
- :exc:`~discord.app_commands.MissingApplicationID`
- :exc:`~discord.MissingApplicationID`
- :exc:`~discord.app_commands.CommandSyncFailure`
- :exc:`~discord.HTTPException`
- :exc:`~discord.app_commands.CommandSyncFailure`