From c79ac4d9fcef90166b406e196af93acc45b02e6c Mon Sep 17 00:00:00 2001 From: Souji Date: Fri, 17 Jul 2020 10:13:30 +0200 Subject: [PATCH] feat(Message): support pin and unpin with reason (#4586) Co-authored-by: SpaceEEC --- src/structures/Message.js | 22 ++++++++++++++++++---- typings/index.d.ts | 4 ++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index bf7216874..fd28c6b7d 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -428,25 +428,39 @@ class Message extends Base { /** * Pins this message to the channel's pinned messages. + * @param {Object} [options] Options for pinning + * @param {string} [options.reason] Reason for pinning * @returns {Promise} + * @example + * // Pin a message with a reason + * message.pin({ reason: 'important' }) + * .then(console.log) + * .catch(console.error) */ - pin() { + pin(options) { return this.client.api .channels(this.channel.id) .pins(this.id) - .put() + .put(options) .then(() => this); } /** * Unpins this message from the channel's pinned messages. + * @param {Object} [options] Options for unpinning + * @param {string} [options.reason] Reason for unpinning * @returns {Promise} + * @example + * // Unpin a message with a reason + * message.unpin({ reason: 'no longer relevant' }) + * .then(console.log) + * .catch(console.error) */ - unpin() { + unpin(options) { return this.client.api .channels(this.channel.id) .pins(this.id) - .delete() + .delete(options) .then(() => this); } diff --git a/typings/index.d.ts b/typings/index.d.ts index 91fe44dec..17e251bae 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -958,7 +958,7 @@ declare module 'discord.js' { public equals(message: Message, rawData: object): boolean; public fetchWebhook(): Promise; public fetch(): Promise; - public pin(): Promise; + public pin(options?: { reason?: string }): Promise; public react(emoji: EmojiIdentifierResolvable): Promise; public reply( content?: StringResolvable, @@ -983,7 +983,7 @@ declare module 'discord.js' { public suppressEmbeds(suppress?: boolean): Promise; public toJSON(): object; public toString(): string; - public unpin(): Promise; + public unpin(options?: { reason?: string }): Promise; } export class MessageAttachment {