4848from .file import File , VoiceMessage
4949from .flags import ChannelFlags , MessageFlags
5050from .invite import Invite
51- from .iterators import HistoryIterator
51+ from .iterators import HistoryIterator , MessagePinIterator
5252from .mentions import AllowedMentions
5353from .partial_emoji import PartialEmoji , _EmojiTag
5454from .permissions import PermissionOverwrite , Permissions
@@ -1765,6 +1765,10 @@ async def pins(self) -> list[Message]:
17651765 objects returned by this method do not contain complete
17661766 :attr:`.Message.reactions` data.
17671767
1768+ .. warning::
1769+
1770+ Starting from version 3.0, this will return a :class:`discord.MessagePinIterator`. See :func:`fetch_pins` for the new behavior.
1771+
17681772 Returns
17691773 -------
17701774 List[:class:`~discord.Message`]
@@ -1775,12 +1779,72 @@ async def pins(self) -> list[Message]:
17751779 ~discord.HTTPException
17761780 Retrieving the pinned messages failed.
17771781 """
1778-
1782+ utils .warn_deprecated (
1783+ f"Messageable.pins() returning a list of Message" ,
1784+ since = "2.7" ,
1785+ removed = "3.0" ,
1786+ reference = "The behavior of fetch_pins"
1787+ )
17791788 channel = await self ._get_channel ()
17801789 state = self ._state
17811790 data = await state .http .legacy_pins_from (channel .id )
17821791 return [state .create_message (channel = channel , data = m ) for m in data ]
17831792
1793+ def fetch_pins (
1794+ self ,
1795+ * ,
1796+ limit : int | None = 50 ,
1797+ before : SnowflakeTime | None = None ,
1798+ ) -> MessagePinIterator :
1799+ """Returns a :class:`~discord.MessagePinIterator` that enables receiving the destination's pinned messages.
1800+
1801+ You must have :attr:`~discord.Permissions.read_message_history` permissions to use this.
1802+
1803+ Parameters
1804+ ----------
1805+ limit: Optional[:class:`int`]
1806+ The number of pinned messages to retrieve.
1807+ If ``None``, retrieves every pinned message in the channel.
1808+ before: Optional[Union[:class:`~discord.abc.Snowflake`, :class:`datetime.datetime`]]
1809+ Retrieve messages pinned before this datetime.
1810+ If a datetime is provided, it is recommended to use a UTC aware datetime.
1811+ If the datetime is naive, it is assumed to be local time.
1812+
1813+ Yields
1814+ ------
1815+ :class:`~discord.MessagePin`
1816+ The pinned message.
1817+
1818+ Raises
1819+ ------
1820+ ~discord.Forbidden
1821+ You do not have permissions to get pinned messages.
1822+ ~discord.HTTPException
1823+ The request to get pinned messages failed.
1824+
1825+ Examples
1826+ --------
1827+
1828+ Usage ::
1829+
1830+ counter = 0
1831+ async for pin in channel.fetch_pins(limit=250):
1832+ if pin.message.author == client.user:
1833+ counter += 1
1834+
1835+ Flattening into a list: ::
1836+
1837+ pins = await channel.fetch_pins(limit=None).flatten()
1838+ # pins is now a list of MessagePin...
1839+
1840+ All parameters are optional.
1841+ """
1842+ return MessagePinIterator (
1843+ self ,
1844+ limit = limit ,
1845+ before = before ,
1846+ )
1847+
17841848 def can_send (self , * objects ) -> bool :
17851849 """Returns a :class:`bool` indicating whether you have the permissions to send the object(s).
17861850
0 commit comments