feat(Message): support pin and unpin with reason (#4586)

Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
This commit is contained in:
Souji
2020-07-17 10:13:30 +02:00
committed by GitHub
parent f9f3661090
commit c79ac4d9fc
2 changed files with 20 additions and 6 deletions

View File

@@ -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<Message>}
* @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<Message>}
* @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);
}

4
typings/index.d.ts vendored
View File

@@ -958,7 +958,7 @@ declare module 'discord.js' {
public equals(message: Message, rawData: object): boolean;
public fetchWebhook(): Promise<Webhook>;
public fetch(): Promise<Message>;
public pin(): Promise<Message>;
public pin(options?: { reason?: string }): Promise<Message>;
public react(emoji: EmojiIdentifierResolvable): Promise<MessageReaction>;
public reply(
content?: StringResolvable,
@@ -983,7 +983,7 @@ declare module 'discord.js' {
public suppressEmbeds(suppress?: boolean): Promise<Message>;
public toJSON(): object;
public toString(): string;
public unpin(): Promise<Message>;
public unpin(options?: { reason?: string }): Promise<Message>;
}
export class MessageAttachment {