diff --git a/packages/discord.js/src/managers/MessageManager.js b/packages/discord.js/src/managers/MessageManager.js index 96622987f..36954c917 100644 --- a/packages/discord.js/src/managers/MessageManager.js +++ b/packages/discord.js/src/managers/MessageManager.js @@ -157,25 +157,27 @@ class MessageManager extends CachedManager { /** * Pins a message to the channel's pinned messages, even if it's not cached. * @param {MessageResolvable} message The message to pin + * @param {string} [reason] Reason for pinning * @returns {Promise} */ - async pin(message) { + async pin(message, reason) { message = this.resolveId(message); if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); - await this.client.rest.put(Routes.channelPins(this.channel.id, message)); + await this.client.rest.put(Routes.channelPins(this.channel.id, message), { reason }); } /** * Unpins a message from the channel's pinned messages, even if it's not cached. * @param {MessageResolvable} message The message to unpin + * @param {string} [reason] Reason for unpinning * @returns {Promise} */ - async unpin(message) { + async unpin(message, reason) { message = this.resolveId(message); if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); - await this.client.rest.delete(Routes.channelPin(this.channel.id, message)); + await this.client.rest.delete(Routes.channelPin(this.channel.id, message), { reason }); } /** diff --git a/packages/discord.js/src/structures/Message.js b/packages/discord.js/src/structures/Message.js index 34c1bc3e0..dd8d28726 100644 --- a/packages/discord.js/src/structures/Message.js +++ b/packages/discord.js/src/structures/Message.js @@ -681,6 +681,7 @@ class Message extends Base { /** * Pins this message to the channel's pinned messages. + * @param {string} [reason] Reason for pinning * @returns {Promise} * @example * // Pin a message @@ -688,14 +689,15 @@ class Message extends Base { * .then(console.log) * .catch(console.error) */ - async pin() { + async pin(reason) { if (!this.channel) throw new Error('CHANNEL_NOT_CACHED'); - await this.channel.messages.pin(this.id); + await this.channel.messages.pin(this.id, reason); return this; } /** * Unpins this message from the channel's pinned messages. + * @param {string} [reason] Reason for unpinning * @returns {Promise} * @example * // Unpin a message @@ -703,9 +705,9 @@ class Message extends Base { * .then(console.log) * .catch(console.error) */ - async unpin() { + async unpin(reason) { if (!this.channel) throw new Error('CHANNEL_NOT_CACHED'); - await this.channel.messages.unpin(this.id); + await this.channel.messages.unpin(this.id, reason); return this; } diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index a86dbf46b..646b7813a 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1525,7 +1525,7 @@ export class Message extends Base { public fetchWebhook(): Promise; public crosspost(): Promise; public fetch(force?: boolean): Promise; - public pin(): Promise; + public pin(reason?: string): Promise; public react(emoji: EmojiIdentifierResolvable): Promise; public removeAttachments(): Promise; public reply(options: string | MessagePayload | ReplyMessageOptions): Promise; @@ -1534,7 +1534,7 @@ export class Message extends Base { public suppressEmbeds(suppress?: boolean): Promise; public toJSON(): unknown; public toString(): string; - public unpin(): Promise; + public unpin(reason?: string): Promise; public inGuild(): this is Message & this; } @@ -2987,8 +2987,8 @@ export class MessageManager extends CachedManager>; public fetchPinned(cache?: boolean): Promise>; public react(message: MessageResolvable, emoji: EmojiIdentifierResolvable): Promise; - public pin(message: MessageResolvable): Promise; - public unpin(message: MessageResolvable): Promise; + public pin(message: MessageResolvable, reason?: string): Promise; + public unpin(message: MessageResolvable, reason?: string): Promise; } export class PermissionOverwriteManager extends CachedManager<