Browse Source

Use new pins endpoints

pull/10205/head
Soheab_ 2 months ago
parent
commit
612657b175
  1. 26
      discord/abc.py
  2. 19
      discord/http.py
  3. 10
      discord/types/message.py

26
discord/abc.py

@ -1710,10 +1710,15 @@ class Messageable:
data = await self._state.http.get_message(channel.id, id)
return self._state.create_message(channel=channel, data=data)
async def pins(self) -> List[Message]:
async def pins(self, *, before: Optional[SnowflakeTime] = None, limit: Optional[int] = None) -> List[Message]:
"""|coro|
Retrieves all messages that are currently pinned in the channel.
Retrieves a maximum of 50 pinned messages from the destination.
Requires the :attr:`~discord.Permissions.view_channel` permission.
No pins will be returned if the user is missing the
:attr:`~discord.Permissions.read_message_history` permission.
.. note::
@ -1721,6 +1726,17 @@ class Messageable:
objects returned by this method do not contain complete
:attr:`.Message.reactions` data.
Parameters
-----------
before: Optional[Union[:class:`~discord.abc.Snowflake`, :class:`datetime.datetime`]]
Retrieve pinned messages before this date or message.
If a datetime is provided, it is recommended to use a UTC aware datetime.
If the datetime is naive, it is assumed to be local time.
limit: Optional[int]
The maximum number of pinned messages to retrieve. Defaults to 50.
This must be a number between 1 and 50.
Raises
-------
~discord.Forbidden
@ -1733,11 +1749,13 @@ class Messageable:
List[:class:`~discord.Message`]
The messages that are currently pinned.
"""
if isinstance(before, datetime):
before = Object(id=utils.time_snowflake(before, high=False))
channel = await self._get_channel()
state = self._state
data = await state.http.pins_from(channel.id)
return [state.create_message(channel=channel, data=m) for m in data]
data = await state.http.pins_from(channel.id, before=before.id if before else None, limit=limit)
return [state.create_message(channel=channel, data=m["message"]) for m in data["items"]]
async def history(
self,

19
discord/http.py

@ -1036,7 +1036,7 @@ class HTTPClient:
def pin_message(self, channel_id: Snowflake, message_id: Snowflake, reason: Optional[str] = None) -> Response[None]:
r = Route(
'PUT',
'/channels/{channel_id}/pins/{message_id}',
'/channels/{channel_id}/messages/pins/{message_id}',
channel_id=channel_id,
message_id=message_id,
)
@ -1045,14 +1045,25 @@ class HTTPClient:
def unpin_message(self, channel_id: Snowflake, message_id: Snowflake, reason: Optional[str] = None) -> Response[None]:
r = Route(
'DELETE',
'/channels/{channel_id}/pins/{message_id}',
'/channels/{channel_id}/messages/pins/{message_id}',
channel_id=channel_id,
message_id=message_id,
)
return self.request(r, reason=reason)
def pins_from(self, channel_id: Snowflake) -> Response[List[message.Message]]:
return self.request(Route('GET', '/channels/{channel_id}/pins', channel_id=channel_id))
def pins_from(
self,
channel_id: Snowflake,
before: Optional[Snowflake] = None,
limit: Optional[int] = None,
) -> Response[message.ChannelPins]:
params = {}
if before is not None:
params['before'] = before
if limit is not None:
params['limit'] = limit
return self.request(Route('GET', '/channels/{channel_id}/messages/pins', channel_id=channel_id), params=params)
# Member management

10
discord/types/message.py

@ -237,3 +237,13 @@ class AllowedMentions(TypedDict):
roles: SnowflakeList
users: SnowflakeList
replied_user: bool
class MessagePin(TypedDict):
pinned_at: str
message: Message
class ChannelPins(TypedDict):
items: List[MessagePin]
has_more: bool

Loading…
Cancel
Save