|
48 | 48 | from .file import File, VoiceMessage
|
49 | 49 | from .flags import ChannelFlags, MessageFlags
|
50 | 50 | from .invite import Invite
|
51 |
| -from .iterators import HistoryIterator |
| 51 | +from .iterators import HistoryIterator, MessagePinIterator |
52 | 52 | from .mentions import AllowedMentions
|
53 | 53 | from .partial_emoji import PartialEmoji, _EmojiTag
|
54 | 54 | from .permissions import PermissionOverwrite, Permissions
|
@@ -1754,32 +1754,64 @@ async def fetch_message(self, id: int, /) -> Message:
|
1754 | 1754 | data = await self._state.http.get_message(channel.id, id)
|
1755 | 1755 | return self._state.create_message(channel=channel, data=data)
|
1756 | 1756 |
|
1757 |
| - async def pins(self) -> list[Message]: |
1758 |
| - """|coro| |
| 1757 | + def pins( |
| 1758 | + self, |
| 1759 | + *, |
| 1760 | + limit: int | None = 50, |
| 1761 | + before: SnowflakeTime | None = None, |
| 1762 | + ) -> MessagePinIterator: |
| 1763 | + """Returns a :class:`~discord.MessagePinIterator` that enables receiving the destination's pinned messages. |
1759 | 1764 |
|
1760 |
| - Retrieves all messages that are currently pinned in the channel. |
| 1765 | + You must have :attr:`~discord.Permissions.read_message_history` permissions to use this. |
1761 | 1766 |
|
1762 |
| - .. note:: |
| 1767 | + .. warning:: |
1763 | 1768 |
|
1764 |
| - Due to a limitation with the Discord API, the :class:`.Message` |
1765 |
| - objects returned by this method do not contain complete |
1766 |
| - :attr:`.Message.reactions` data. |
| 1769 | + Starting from version 3.0, `await channel.pins()` will no longer return a list of :class:`Message`. See examples below for new usage instead. |
1767 | 1770 |
|
1768 |
| - Returns |
1769 |
| - ------- |
1770 |
| - List[:class:`~discord.Message`] |
1771 |
| - The messages that are currently pinned. |
| 1771 | + Parameters |
| 1772 | + ---------- |
| 1773 | + limit: Optional[:class:`int`] |
| 1774 | + The number of pinned messages to retrieve. |
| 1775 | + If ``None``, retrieves every pinned message in the channel. |
| 1776 | + before: Optional[Union[:class:`~discord.abc.Snowflake`, :class:`datetime.datetime`]] |
| 1777 | + Retrieve messages pinned before this datetime. |
| 1778 | + If a datetime is provided, it is recommended to use a UTC aware datetime. |
| 1779 | + If the datetime is naive, it is assumed to be local time. |
| 1780 | +
|
| 1781 | + Yields |
| 1782 | + ------ |
| 1783 | + :class:`~discord.MessagePin` |
| 1784 | + The pinned message. |
1772 | 1785 |
|
1773 | 1786 | Raises
|
1774 | 1787 | ------
|
| 1788 | + ~discord.Forbidden |
| 1789 | + You do not have permissions to get pinned messages. |
1775 | 1790 | ~discord.HTTPException
|
1776 |
| - Retrieving the pinned messages failed. |
1777 |
| - """ |
| 1791 | + The request to get pinned messages failed. |
1778 | 1792 |
|
1779 |
| - channel = await self._get_channel() |
1780 |
| - state = self._state |
1781 |
| - data = await state.http.pins_from(channel.id) |
1782 |
| - return [state.create_message(channel=channel, data=m) for m in data] |
| 1793 | + Examples |
| 1794 | + -------- |
| 1795 | +
|
| 1796 | + Usage :: |
| 1797 | +
|
| 1798 | + counter = 0 |
| 1799 | + async for pin in channel.pins(limit=250): |
| 1800 | + if pin.message.author == client.user: |
| 1801 | + counter += 1 |
| 1802 | +
|
| 1803 | + Flattening into a list: :: |
| 1804 | +
|
| 1805 | + pins = await channel.pins(limit=None).flatten() |
| 1806 | + # pins is now a list of MessagePin... |
| 1807 | +
|
| 1808 | + All parameters are optional. |
| 1809 | + """ |
| 1810 | + return MessagePinIterator( |
| 1811 | + self, |
| 1812 | + limit=limit, |
| 1813 | + before=before, |
| 1814 | + ) |
1783 | 1815 |
|
1784 | 1816 | def can_send(self, *objects) -> bool:
|
1785 | 1817 | """Returns a :class:`bool` indicating whether you have the permissions to send the object(s).
|
|
0 commit comments