Source code for discord.channel.partial

"""
The MIT License (MIT)

Copyright (c) 2015-2021 Rapptz
Copyright (c) 2021-present Pycord Development

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""

from __future__ import annotations

from typing import TYPE_CHECKING

from ..abc import Messageable
from ..enums import ChannelType
from ..mixins import Hashable
from ..object import Object

if TYPE_CHECKING:
    from ..message import PartialMessage
    from ..state import ConnectionState

__all__ = ("PartialMessageable",)


[docs] class PartialMessageable(Messageable, Hashable): """Represents a partial messageable to aid with working messageable channels when only a channel ID are present. The only way to construct this class is through :meth:`Client.get_partial_messageable`. Note that this class is trimmed down and has no rich attributes. .. versionadded:: 2.0 .. container:: operations .. describe:: x == y Checks if two partial messageables are equal. .. describe:: x != y Checks if two partial messageables are not equal. .. describe:: hash(x) Returns the partial messageable's hash. Attributes ---------- id: :class:`int` The channel ID associated with this partial messageable. type: Optional[:class:`ChannelType`] The channel type associated with this partial messageable, if given. """ def __init__(self, state: ConnectionState, id: int, type: ChannelType | None = None): self._state: ConnectionState = state self._channel: Object = Object(id=id) self.id: int = id self.type: ChannelType | None = type async def _get_channel(self) -> Object: return self._channel
[docs] def get_partial_message(self, message_id: int, /) -> PartialMessage: """Creates a :class:`PartialMessage` from the message ID. This is useful if you want to work with a message and only have its ID without doing an unnecessary API call. Parameters ---------- message_id: :class:`int` The message ID to create a partial message for. Returns ------- :class:`PartialMessage` The partial message. """ from ..message import PartialMessage return PartialMessage(channel=self, id=message_id)
def __repr__(self) -> str: return f"<PartialMessageable id={self.id} type={self.type!r}>"