Skip to content

Commit df4b1c8

Browse files
committed
Move MissingApplicationID to top-level discord namespace
1 parent 66d7405 commit df4b1c8

File tree

8 files changed

+39
-26
lines changed

8 files changed

+39
-26
lines changed

discord/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,10 @@ class VersionInfo(NamedTuple):
8484

8585
logging.getLogger(__name__).addHandler(logging.NullHandler())
8686

87+
# This is a backwards compatibility hack and should be removed in v3
88+
# Essentially forcing the exception to have different base classes
89+
# In the future, this should only inherit from ClientException
90+
if len(MissingApplicationID.__bases__) == 1:
91+
MissingApplicationID.__bases__ = (app_commands.AppCommandError, ClientException)
92+
8793
del logging, NamedTuple, Literal, VersionInfo

discord/app_commands/errors.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from typing import Any, TYPE_CHECKING, List, Optional, Sequence, Union
2828

2929
from ..enums import AppCommandOptionType, AppCommandType, Locale
30-
from ..errors import DiscordException, HTTPException, _flatten_error_dict
30+
from ..errors import DiscordException, HTTPException, _flatten_error_dict, MissingApplicationID as MissingApplicationID
3131
from ..utils import _human_join
3232

3333
__all__ = (
@@ -59,11 +59,6 @@
5959

6060
CommandTypes = Union[Command[Any, ..., Any], Group, ContextMenu]
6161

62-
APP_ID_NOT_FOUND = (
63-
'Client does not have an application_id set. Either the function was called before on_ready '
64-
'was called or application_id was not passed to the Client constructor.'
65-
)
66-
6762

6863
class AppCommandError(DiscordException):
6964
"""The base exception type for all application command related errors.
@@ -422,19 +417,6 @@ def __init__(self, command: Union[Command[Any, ..., Any], ContextMenu, Group]):
422417
super().__init__(msg)
423418

424419

425-
class MissingApplicationID(AppCommandError):
426-
"""An exception raised when the client does not have an application ID set.
427-
An application ID is required for syncing application commands.
428-
429-
This inherits from :exc:`~discord.app_commands.AppCommandError`.
430-
431-
.. versionadded:: 2.0
432-
"""
433-
434-
def __init__(self, message: Optional[str] = None):
435-
super().__init__(message or APP_ID_NOT_FOUND)
436-
437-
438420
def _get_command_error(
439421
index: str,
440422
inner: Any,

discord/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
from typing_extensions import Self
8585

8686
from .abc import Messageable, PrivateChannel, Snowflake, SnowflakeTime
87-
from .app_commands import Command, ContextMenu, MissingApplicationID
87+
from .app_commands import Command, ContextMenu
8888
from .automod import AutoModAction, AutoModRule
8989
from .channel import DMChannel, GroupChannel
9090
from .ext.commands import AutoShardedBot, Bot, Context, CommandError

discord/emoji.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from .utils import SnowflakeList, snowflake_time, MISSING
3030
from .partial_emoji import _EmojiTag, PartialEmoji
3131
from .user import User
32-
from .app_commands.errors import MissingApplicationID
32+
from .errors import MissingApplicationID
3333
from .object import Object
3434

3535
# fmt: off

discord/errors.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
'ConnectionClosed',
4848
'PrivilegedIntentsRequired',
4949
'InteractionResponded',
50+
'MissingApplicationID',
51+
)
52+
53+
APP_ID_NOT_FOUND = (
54+
'Client does not have an application_id set. Either the function was called before on_ready '
55+
'was called or application_id was not passed to the Client constructor.'
5056
)
5157

5258

@@ -278,3 +284,22 @@ class InteractionResponded(ClientException):
278284
def __init__(self, interaction: Interaction):
279285
self.interaction: Interaction = interaction
280286
super().__init__('This interaction has already been responded to before')
287+
288+
289+
class MissingApplicationID(ClientException):
290+
"""An exception raised when the client does not have an application ID set.
291+
292+
An application ID is required for syncing application commands and various
293+
other application tasks such as SKUs or application emojis.
294+
295+
This inherits from :exc:`~discord.app_commands.AppCommandError`
296+
and :class:`~discord.ClientException`.
297+
298+
.. versionadded:: 2.0
299+
300+
.. versionchanged:: 2.5
301+
This is now exported to the ``discord`` namespace and now inherits from :class:`~discord.ClientException`.
302+
"""
303+
304+
def __init__(self, message: Optional[str] = None):
305+
super().__init__(message or APP_ID_NOT_FOUND)

discord/sku.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from typing import Optional, TYPE_CHECKING
2929

3030
from . import utils
31-
from .app_commands import MissingApplicationID
31+
from .errors import MissingApplicationID
3232
from .enums import try_enum, SKUType, EntitlementType
3333
from .flags import SKUFlags
3434

docs/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5440,6 +5440,8 @@ The following exceptions are thrown by the library.
54405440

54415441
.. autoexception:: InteractionResponded
54425442

5443+
.. autoexception:: MissingApplicationID
5444+
54435445
.. autoexception:: discord.opus.OpusError
54445446

54455447
.. autoexception:: discord.opus.OpusNotLoaded
@@ -5457,6 +5459,7 @@ Exception Hierarchy
54575459
- :exc:`ConnectionClosed`
54585460
- :exc:`PrivilegedIntentsRequired`
54595461
- :exc:`InteractionResponded`
5462+
- :exc:`MissingApplicationID`
54605463
- :exc:`GatewayNotFound`
54615464
- :exc:`HTTPException`
54625465
- :exc:`Forbidden`

docs/interactions/api.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -872,9 +872,6 @@ Exceptions
872872
.. autoexception:: discord.app_commands.CommandNotFound
873873
:members:
874874

875-
.. autoexception:: discord.app_commands.MissingApplicationID
876-
:members:
877-
878875
.. autoexception:: discord.app_commands.CommandSyncFailure
879876
:members:
880877

@@ -899,7 +896,7 @@ Exception Hierarchy
899896
- :exc:`~discord.app_commands.CommandAlreadyRegistered`
900897
- :exc:`~discord.app_commands.CommandSignatureMismatch`
901898
- :exc:`~discord.app_commands.CommandNotFound`
902-
- :exc:`~discord.app_commands.MissingApplicationID`
899+
- :exc:`~discord.MissingApplicationID`
903900
- :exc:`~discord.app_commands.CommandSyncFailure`
904901
- :exc:`~discord.HTTPException`
905902
- :exc:`~discord.app_commands.CommandSyncFailure`

0 commit comments

Comments
 (0)