Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Rapptz/discord.py into v2…
Browse files Browse the repository at this point in the history
…-martine
  • Loading branch information
PredaaA committed Sep 6, 2024
2 parents 4fa164e + 59f877f commit ded4a25
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 41 deletions.
6 changes: 6 additions & 0 deletions discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,10 @@ class VersionInfo(NamedTuple):

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
20 changes: 1 addition & 19 deletions discord/app_commands/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
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__ = (
Expand Down Expand Up @@ -59,11 +59,6 @@

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.
Expand Down Expand Up @@ -422,19 +417,6 @@ def __init__(self, command: Union[Command[Any, ..., Any], ContextMenu, Group]):
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,
Expand Down
2 changes: 1 addition & 1 deletion discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion discord/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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
Expand Down
25 changes: 25 additions & 0 deletions discord/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
'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.'
)


Expand Down Expand Up @@ -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)
4 changes: 1 addition & 3 deletions discord/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1843,13 +1843,11 @@ def __init__(
self.application_id: Optional[int] = utils._get_as_snowflake(data, 'application_id')
self.stickers: List[StickerItem] = [StickerItem(data=d, state=state) for d in data.get('sticker_items', [])]

# This updates the poll so it has the counts, if the message
# was previously cached.
self.poll: Optional[Poll] = None
try:
self.poll = Poll._from_data(data=data['poll'], message=self, state=state)
except KeyError:
self.poll = state._get_poll(self.id)
pass

try:
# if the channel doesn't have a guild attribute, we handle that
Expand Down
2 changes: 1 addition & 1 deletion discord/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def all(cls) -> Self:
permissions set to ``True``.
"""
# Some of these are 0 because we don't want to set unnecessary bits
return cls(0b0000_0000_0000_0010_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111)
return cls(0b0000_0000_0000_0110_0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111)

@classmethod
def _timeout_mask(cls) -> int:
Expand Down
2 changes: 1 addition & 1 deletion discord/sku.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
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

Expand Down
6 changes: 0 additions & 6 deletions discord/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,6 @@ def _remove_private_channel(self, channel: PrivateChannel) -> None:
def _get_message(self, msg_id: Optional[int]) -> Optional[Message]:
return utils.find(lambda m: m.id == msg_id, reversed(self._messages)) if self._messages else None

def _get_poll(self, msg_id: Optional[int]) -> Optional[Poll]:
message = self._get_message(msg_id)
if not message:
return
return message.poll

def _add_guild_from_data(self, data: GuildPayload) -> Guild:
guild = Guild(data=data, state=self)
self._add_guild(guild)
Expand Down
5 changes: 0 additions & 5 deletions discord/webhook/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,11 +721,6 @@ def _get_guild(self, guild_id: Optional[int]) -> Optional[Guild]:
return self._parent._get_guild(guild_id)
return None

def _get_poll(self, msg_id: Optional[int]) -> Optional[Poll]:
if self._parent is not None:
return self._parent._get_poll(msg_id)
return None

def store_user(self, data: Union[UserPayload, PartialUserPayload], *, cache: bool = True) -> BaseUser:
if self._parent is not None:
return self._parent.store_user(data, cache=cache)
Expand Down
3 changes: 3 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5440,6 +5440,8 @@ The following exceptions are thrown by the library.

.. autoexception:: InteractionResponded

.. autoexception:: MissingApplicationID

.. autoexception:: discord.opus.OpusError

.. autoexception:: discord.opus.OpusNotLoaded
Expand All @@ -5457,6 +5459,7 @@ Exception Hierarchy
- :exc:`ConnectionClosed`
- :exc:`PrivilegedIntentsRequired`
- :exc:`InteractionResponded`
- :exc:`MissingApplicationID`
- :exc:`GatewayNotFound`
- :exc:`HTTPException`
- :exc:`Forbidden`
Expand Down
5 changes: 1 addition & 4 deletions docs/interactions/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -872,9 +872,6 @@ Exceptions
.. autoexception:: discord.app_commands.CommandNotFound
:members:

.. autoexception:: discord.app_commands.MissingApplicationID
:members:

.. autoexception:: discord.app_commands.CommandSyncFailure
:members:

Expand All @@ -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`
7 changes: 7 additions & 0 deletions tests/test_permissions_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import discord

from functools import reduce
from operator import or_

def test_permissions_all():
assert discord.Permissions.all().value == reduce(or_, discord.Permissions.VALID_FLAGS.values())

0 comments on commit ded4a25

Please sign in to comment.