Skip to content

Commit b231bec

Browse files
authored
feat: Backport reason on pin and unpin (#7556)
1 parent 49397c0 commit b231bec

3 files changed

Lines changed: 16 additions & 12 deletions

File tree

src/managers/MessageManager.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,25 +156,27 @@ class MessageManager extends CachedManager {
156156
/**
157157
* Pins a message to the channel's pinned messages, even if it's not cached.
158158
* @param {MessageResolvable} message The message to pin
159+
* @param {string} [reason] Reason for pinning
159160
* @returns {Promise<void>}
160161
*/
161-
async pin(message) {
162+
async pin(message, reason) {
162163
message = this.resolveId(message);
163164
if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');
164165

165-
await this.client.api.channels(this.channel.id).pins(message).put();
166+
await this.client.api.channels(this.channel.id).pins(message).put({ reason });
166167
}
167168

168169
/**
169170
* Unpins a message from the channel's pinned messages, even if it's not cached.
170171
* @param {MessageResolvable} message The message to unpin
172+
* @param {string} [reason] Reason for unpinning
171173
* @returns {Promise<void>}
172174
*/
173-
async unpin(message) {
175+
async unpin(message, reason) {
174176
message = this.resolveId(message);
175177
if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');
176178

177-
await this.client.api.channels(this.channel.id).pins(message).delete();
179+
await this.client.api.channels(this.channel.id).pins(message).delete({ reason });
178180
}
179181

180182
/**

src/structures/Message.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,31 +720,33 @@ class Message extends Base {
720720

721721
/**
722722
* Pins this message to the channel's pinned messages.
723+
* @param {string} [reason] Reason for pinning
723724
* @returns {Promise<Message>}
724725
* @example
725726
* // Pin a message
726727
* message.pin()
727728
* .then(console.log)
728729
* .catch(console.error)
729730
*/
730-
async pin() {
731+
async pin(reason) {
731732
if (!this.channel) throw new Error('CHANNEL_NOT_CACHED');
732-
await this.channel.messages.pin(this.id);
733+
await this.channel.messages.pin(this.id, reason);
733734
return this;
734735
}
735736

736737
/**
737738
* Unpins this message from the channel's pinned messages.
739+
* @param {string} [reason] Reason for unpinning
738740
* @returns {Promise<Message>}
739741
* @example
740742
* // Unpin a message
741743
* message.unpin()
742744
* .then(console.log)
743745
* .catch(console.error)
744746
*/
745-
async unpin() {
747+
async unpin(reason) {
746748
if (!this.channel) throw new Error('CHANNEL_NOT_CACHED');
747-
await this.channel.messages.unpin(this.id);
749+
await this.channel.messages.unpin(this.id, reason);
748750
return this;
749751
}
750752

typings/index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ export class Message<Cached extends boolean = boolean> extends Base {
15461546
public fetchWebhook(): Promise<Webhook>;
15471547
public crosspost(): Promise<Message>;
15481548
public fetch(force?: boolean): Promise<Message>;
1549-
public pin(): Promise<Message>;
1549+
public pin(reason?: string): Promise<Message>;
15501550
public react(emoji: EmojiIdentifierResolvable): Promise<MessageReaction>;
15511551
public removeAttachments(): Promise<Message>;
15521552
public reply(options: string | MessagePayload | ReplyMessageOptions): Promise<Message>;
@@ -1555,7 +1555,7 @@ export class Message<Cached extends boolean = boolean> extends Base {
15551555
public suppressEmbeds(suppress?: boolean): Promise<Message>;
15561556
public toJSON(): unknown;
15571557
public toString(): string;
1558-
public unpin(): Promise<Message>;
1558+
public unpin(reason?: string): Promise<Message>;
15591559
public inGuild(): this is Message<true> & this;
15601560
}
15611561

@@ -3174,8 +3174,8 @@ export class MessageManager extends CachedManager<Snowflake, Message, MessageRes
31743174
): Promise<Collection<Snowflake, Message>>;
31753175
public fetchPinned(cache?: boolean): Promise<Collection<Snowflake, Message>>;
31763176
public react(message: MessageResolvable, emoji: EmojiIdentifierResolvable): Promise<void>;
3177-
public pin(message: MessageResolvable): Promise<void>;
3178-
public unpin(message: MessageResolvable): Promise<void>;
3177+
public pin(message: MessageResolvable, reason?: string): Promise<void>;
3178+
public unpin(message: MessageResolvable, reason?: string): Promise<void>;
31793179
}
31803180

31813181
export class PermissionOverwriteManager extends CachedManager<

0 commit comments

Comments
 (0)