|
70 | 70 | from .enums import InviteTarget |
71 | 71 | from .guild import Guild, GuildChannel as AnyGuildChannel, GuildMessageable |
72 | 72 | from .guild_scheduled_event import GuildScheduledEvent |
73 | | - from .iterators import HistoryIterator |
| 73 | + from .iterators import ChannelPinsIterator, HistoryIterator |
74 | 74 | from .member import Member |
75 | 75 | from .message import Message, MessageReference, PartialMessage |
76 | 76 | from .poll import Poll |
@@ -1863,31 +1863,64 @@ async def fetch_message(self, id: int, /) -> Message: |
1863 | 1863 | data = await self._state.http.get_message(channel.id, id) |
1864 | 1864 | return self._state.create_message(channel=channel, data=data) |
1865 | 1865 |
|
1866 | | - async def pins(self) -> List[Message]: |
1867 | | - """|coro| |
| 1866 | + def pins( |
| 1867 | + self, *, limit: Optional[int] = 50, before: Optional[SnowflakeTime] = None |
| 1868 | + ) -> ChannelPinsIterator: |
| 1869 | + """Returns an :class:`.AsyncIterator` that enables receiving the destination's pinned messages. |
1868 | 1870 |
|
1869 | | - Retrieves all messages that are currently pinned in the channel. |
| 1871 | + You must have the :attr:`.Permissions.read_message_history` and :attr:`.Permissions.view_channel` permissions to use this. |
1870 | 1872 |
|
1871 | 1873 | .. note:: |
1872 | 1874 |
|
1873 | 1875 | Due to a limitation with the Discord API, the :class:`.Message` |
1874 | 1876 | objects returned by this method do not contain complete |
1875 | 1877 | :attr:`.Message.reactions` data. |
1876 | 1878 |
|
| 1879 | + .. versionchanged:: 2.11 |
| 1880 | + Now returns an :class:`.AsyncIterator` to support changes in Discord's API. |
| 1881 | + ``await``\\ing the result of this method remains supported, but only returns the |
| 1882 | + last 50 pins and is deprecated in favor of ``async for msg in channel.pins()``. |
| 1883 | +
|
| 1884 | + Examples |
| 1885 | + -------- |
| 1886 | + Usage :: |
| 1887 | +
|
| 1888 | + counter = 0 |
| 1889 | + async for message in channel.pins(limit=100): |
| 1890 | + if message.author == client.user: |
| 1891 | + counter += 1 |
| 1892 | +
|
| 1893 | + Flattening to a list :: |
| 1894 | +
|
| 1895 | + pinned_messages = await channel.pins(limit=100).flatten() |
| 1896 | + # pinned_messages is now a list of Message... |
| 1897 | +
|
| 1898 | + All parameters are optional. |
| 1899 | +
|
| 1900 | + Parameters |
| 1901 | + ---------- |
| 1902 | + limit: Optional[:class:`int`] |
| 1903 | + The number of pinned messages to retrieve. |
| 1904 | + If ``None``, retrieves every pinned message in the channel. Note, however, |
| 1905 | + that this would make it a slow operation. |
| 1906 | + before: Optional[Union[:class:`.abc.Snowflake`, :class:`datetime.datetime`]] |
| 1907 | + Retrieve messages pinned before this date or message. |
| 1908 | + If a datetime is provided, it is recommended to use a UTC aware datetime. |
| 1909 | + If the datetime is naive, it is assumed to be local time. |
| 1910 | +
|
1877 | 1911 | Raises |
1878 | 1912 | ------ |
1879 | 1913 | HTTPException |
1880 | 1914 | Retrieving the pinned messages failed. |
1881 | 1915 |
|
1882 | | - Returns |
1883 | | - ------- |
1884 | | - List[:class:`.Message`] |
1885 | | - The messages that are currently pinned. |
| 1916 | + Yields |
| 1917 | + ------ |
| 1918 | + :class:`.Message` |
| 1919 | + The pinned message from the parsed message data. |
1886 | 1920 | """ |
1887 | | - channel = await self._get_channel() |
1888 | | - state = self._state |
1889 | | - data = await state.http.pins_from(channel.id) |
1890 | | - return [state.create_message(channel=channel, data=m) for m in data] |
| 1921 | + from .iterators import ChannelPinsIterator # due to cyclic imports |
| 1922 | + |
| 1923 | + return ChannelPinsIterator(self, limit=limit, before=before) |
1891 | 1924 |
|
1892 | 1925 | def history( |
1893 | 1926 | self, |
|
0 commit comments