@@ -123,24 +123,63 @@ class MessageManager extends CachedManager {
123123 return data . reduce ( ( _data , message ) => _data . set ( message . id , this . _add ( message , options . cache ) ) , new Collection ( ) ) ;
124124 }
125125
126+ /**
127+ * Options used to fetch pinned messages.
128+ *
129+ * @typedef {Object } FetchPinnedMessagesOptions
130+ * @property {DateResolvable } [before] Consider only pinned messages before this time
131+ * @property {number } [limit] The maximum number of pinned messages to return
132+ * @property {boolean } [cache] Whether to cache the pinned messages
133+ */
134+
135+ /**
136+ * Data returned from fetching pinned messages.
137+ *
138+ * @typedef {Object } FetchPinnedMessagesResponse
139+ * @property {MessagePin[] } items The pinned messages
140+ * @property {boolean } hasMore Whether there are additional pinned messages that require a subsequent call
141+ */
142+
143+ /**
144+ * Pinned message data returned from fetching pinned messages.
145+ *
146+ * @typedef {Object } MessagePin
147+ * @property {Date } pinnedAt The time the message was pinned at
148+ * @property {number } pinnedTimestamp The timestamp the message was pinned at
149+ * @property {Message } message The pinned message
150+ */
151+
126152 /**
127153 * Fetches the pinned messages of this channel and returns a collection of them.
128154 * <info>The returned Collection does not contain any reaction data of the messages.
129155 * Those need to be fetched separately.</info>
130156 *
131- * @param {boolean } [cache=true] Whether to cache the message(s)
132- * @returns {Promise<Collection<Snowflake, Message> > }
157+ * @param {FetchPinnedMessagesOptions } [options={}] Options for fetching pinned messages
158+ * @returns {Promise<FetchPinnedMessagesResponse > }
133159 * @example
134160 * // Get pinned messages
135- * channel.messages.fetchPinned ()
136- * .then(messages => console.log(`Received ${messages.size } messages`))
161+ * channel.messages.fetchPins ()
162+ * .then(messages => console.log(`Received ${messages.items.length } messages`))
137163 * .catch(console.error);
138164 */
139- async fetchPinned ( cache = true ) {
140- const data = await this . client . rest . get ( Routes . channelPins ( this . channel . id ) ) ;
141- const messages = new Collection ( ) ;
142- for ( const message of data ) messages . set ( message . id , this . _add ( message , cache ) ) ;
143- return messages ;
165+ async fetchPins ( options = { } ) {
166+ const data = await this . client . rest . get ( Routes . channelMessagesPins ( this . channel . id ) , {
167+ query : makeURLSearchParams ( {
168+ ...options ,
169+ before : options . before && new Date ( options . before ) . toISOString ( ) ,
170+ } ) ,
171+ } ) ;
172+
173+ return {
174+ items : data . items . map ( item => ( {
175+ pinnedTimestamp : Date . parse ( item . pinned_at ) ,
176+ get pinnedAt ( ) {
177+ return new Date ( this . pinnedTimestamp ) ;
178+ } ,
179+ message : this . _add ( item . message , options . cache ) ,
180+ } ) ) ,
181+ hasMore : data . has_more ,
182+ } ;
144183 }
145184
146185 /**
@@ -221,7 +260,7 @@ class MessageManager extends CachedManager {
221260 const messageId = this . resolveId ( message ) ;
222261 if ( ! messageId ) throw new DiscordjsTypeError ( ErrorCodes . InvalidType , 'message' , 'MessageResolvable' ) ;
223262
224- await this . client . rest . put ( Routes . channelPin ( this . channel . id , messageId ) , { reason } ) ;
263+ await this . client . rest . put ( Routes . channelMessagesPin ( this . channel . id , messageId ) , { reason } ) ;
225264 }
226265
227266 /**
@@ -235,7 +274,7 @@ class MessageManager extends CachedManager {
235274 const messageId = this . resolveId ( message ) ;
236275 if ( ! messageId ) throw new DiscordjsTypeError ( ErrorCodes . InvalidType , 'message' , 'MessageResolvable' ) ;
237276
238- await this . client . rest . delete ( Routes . channelPin ( this . channel . id , messageId ) , { reason } ) ;
277+ await this . client . rest . delete ( Routes . channelMessagesPin ( this . channel . id , messageId ) , { reason } ) ;
239278 }
240279
241280 /**
0 commit comments