feat(message): add reason on pin and unpin (#7520)

This commit is contained in:
Almeida
2022-02-23 07:38:50 +00:00
committed by GitHub
parent 4f306521d8
commit 00728f72b3
3 changed files with 16 additions and 12 deletions

View File

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

View File

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

View File

@@ -1525,7 +1525,7 @@ export class Message<Cached extends boolean = boolean> extends Base {
public fetchWebhook(): Promise<Webhook>;
public crosspost(): Promise<Message>;
public fetch(force?: boolean): Promise<Message>;
public pin(): Promise<Message>;
public pin(reason?: string): Promise<Message>;
public react(emoji: EmojiIdentifierResolvable): Promise<MessageReaction>;
public removeAttachments(): Promise<Message>;
public reply(options: string | MessagePayload | ReplyMessageOptions): Promise<Message>;
@@ -1534,7 +1534,7 @@ export class Message<Cached extends boolean = boolean> extends Base {
public suppressEmbeds(suppress?: boolean): Promise<Message>;
public toJSON(): unknown;
public toString(): string;
public unpin(): Promise<Message>;
public unpin(reason?: string): Promise<Message>;
public inGuild(): this is Message<true> & this;
}
@@ -2987,8 +2987,8 @@ export class MessageManager extends CachedManager<Snowflake, Message, MessageRes
): Promise<Collection<Snowflake, Message>>;
public fetchPinned(cache?: boolean): Promise<Collection<Snowflake, Message>>;
public react(message: MessageResolvable, emoji: EmojiIdentifierResolvable): Promise<void>;
public pin(message: MessageResolvable): Promise<void>;
public unpin(message: MessageResolvable): Promise<void>;
public pin(message: MessageResolvable, reason?: string): Promise<void>;
public unpin(message: MessageResolvable, reason?: string): Promise<void>;
}
export class PermissionOverwriteManager extends CachedManager<