From dfb2a206ef195932000d31a280fc3e961fae6699 Mon Sep 17 00:00:00 2001 From: Monbrey Date: Mon, 14 Sep 2020 12:09:31 +1000 Subject: [PATCH 01/28] feat(MessageManager): move Message#edit API calls to Manager --- src/managers/MessageManager.js | 22 ++++++++++++++++++++++ src/structures/Message.js | 8 +------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index f6a0011c2e31..0334593d3e20 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -1,6 +1,7 @@ 'use strict'; const BaseManager = require('./BaseManager'); +const APIMessage = require('../structures/APIMessage'); const Message = require('../structures/Message'); const Collection = require('../util/Collection'); const LimitedCollection = require('../util/LimitedCollection'); @@ -112,6 +113,27 @@ class MessageManager extends BaseManager { * @returns {?Snowflake} */ + /** + * Edits a message, even if it's not cached. + * @param {MessageResolvable} message The message to delete + * @param {StringResolvable|APIMessage} [content] The new content for the message + * @param {MessageEditOptions|MessageEmbed} [options] The options to provide + * @returns {Promise} + */ + async edit(message, content, options) { + message = this.resolveID(message); + if (message) { + const { data } = + content instanceof APIMessage ? content.resolveData() : APIMessage.create(this, content, options).resolveData(); + await this.client.api.channels[this.channel.id].messages[message].patch({ data }).then(d => { + if (this.cache.has(message)) { + const clone = this.cache.get(message)._clone(); + clone._patch(d); + } + }); + } + } + /** * Deletes a message, even if it's not cached. * @param {MessageResolvable} message The message to delete diff --git a/src/structures/Message.js b/src/structures/Message.js index 22a0de773bd6..0789fbc64bc4 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -439,13 +439,7 @@ class Message extends Base { * .catch(console.error); */ edit(content, options) { - const { data } = - content instanceof APIMessage ? content.resolveData() : APIMessage.create(this, content, options).resolveData(); - return this.client.api.channels[this.channel.id].messages[this.id].patch({ data }).then(d => { - const clone = this._clone(); - clone._patch(d); - return clone; - }); + return this.channel.messages.edit(this.id, content, options).then(() => this); } /** From e9855f41c2b50c7f1203fd223e239ad607d47daf Mon Sep 17 00:00:00 2001 From: Monbrey Date: Mon, 14 Sep 2020 18:40:10 +1000 Subject: [PATCH 02/28] fix(MessageEditOptions): update method reference --- src/structures/Message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index 0789fbc64bc4..ac45d57447ff 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -419,7 +419,7 @@ class Message extends Base { } /** - * Options that can be passed into editMessage. + * Options that can be passed into Message#edit. * @typedef {Object} MessageEditOptions * @property {string} [content] Content to be edited * @property {MessageEmbed|Object} [embed] An embed to be added/edited From 909b7d7dfcc700f11ec98f81a694ba99e07532f4 Mon Sep 17 00:00:00 2001 From: Monbrey Date: Tue, 15 Sep 2020 09:15:55 +1000 Subject: [PATCH 03/28] feat(MessageManager): move Message#crosspost API calls to Manager --- src/managers/MessageManager.js | 14 +++++++++++++- src/structures/Message.js | 5 ++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index 0334593d3e20..e5f0f169f98c 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -115,7 +115,7 @@ class MessageManager extends BaseManager { /** * Edits a message, even if it's not cached. - * @param {MessageResolvable} message The message to delete + * @param {MessageResolvable} message The message to edit * @param {StringResolvable|APIMessage} [content] The new content for the message * @param {MessageEditOptions|MessageEmbed} [options] The options to provide * @returns {Promise} @@ -134,6 +134,18 @@ class MessageManager extends BaseManager { } } + /** + * Publishes a message in an announcement channel to all channels following it, even if it's not cached. + * @param {MessageResolvable} message The message to publish + * @returns {Promise} + */ + async crosspost(message) { + message = this.resolveID(message); + if (message) { + await this.client.api.channels(this.channel.id).messages(message).crosspost.post(); + } + } + /** * Deletes a message, even if it's not cached. * @param {MessageResolvable} message The message to delete diff --git a/src/structures/Message.js b/src/structures/Message.js index ac45d57447ff..f9eb60bedfb7 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -453,9 +453,8 @@ class Message extends Base { * .catch(console.error); * } */ - async crosspost() { - await this.client.api.channels(this.channel.id).messages(this.id).crosspost.post(); - return this; + crosspost() { + return this.channel.messages.crosspost(this.id).then(() => this); } /** From 0afb29215844573f11c2126ae8829817105d2186 Mon Sep 17 00:00:00 2001 From: Monbrey Date: Wed, 16 Sep 2020 08:03:02 +1000 Subject: [PATCH 04/28] feat(MessageManager): move Message#pin API calls to Manager --- src/managers/MessageManager.js | 18 ++++++++++++++++++ src/structures/Message.js | 6 +----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index e5f0f169f98c..bc5ac3d61cb0 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -146,6 +146,24 @@ class MessageManager extends BaseManager { } } + /** + * Pins a message to the channel's pinned messages, even if it's not cached. + * @param {MessageResolvable} message The message to pin + * @param {Object} [options] Options for pinning + * @param {string} [options.reason] Reason for pinning + * @returns {Promise} + */ + async pin(message, options) { + message = this.resolveID(message); + if (message) { + await this.client.api + .channels(this.channel.id) + .pins(message) + .put(options) + .then(() => this); + } + } + /** * Deletes a message, even if it's not cached. * @param {MessageResolvable} message The message to delete diff --git a/src/structures/Message.js b/src/structures/Message.js index f9eb60bedfb7..1bd3f95f1272 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -469,11 +469,7 @@ class Message extends Base { * .catch(console.error) */ pin(options) { - return this.client.api - .channels(this.channel.id) - .pins(this.id) - .put(options) - .then(() => this); + return this.channel.messages.pin(this.id, options).then(() => this); } /** From ffb94caade4c7e15441d71f43e754b60dc9919f2 Mon Sep 17 00:00:00 2001 From: Monbrey Date: Wed, 16 Sep 2020 08:04:15 +1000 Subject: [PATCH 05/28] feat(MessageManager): move Message#unpin API calls to Manager --- src/managers/MessageManager.js | 18 ++++++++++++++++++ src/structures/Message.js | 6 +----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index bc5ac3d61cb0..0418c1141421 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -164,6 +164,24 @@ class MessageManager extends BaseManager { } } + /** + * Unins a message from the channel's pinned messages, even if it's not cached. + * @param {MessageResolvable} message The message to unpin + * @param {Object} [options] Options for unpinning + * @param {string} [options.reason] Reason for unpinning + * @returns {Promise} + */ + async unpin(message, options) { + message = this.resolveID(message); + if (message) { + await this.client.api + .channels(this.channel.id) + .pins(message) + .delete(options) + .then(() => this); + } + } + /** * Deletes a message, even if it's not cached. * @param {MessageResolvable} message The message to delete diff --git a/src/structures/Message.js b/src/structures/Message.js index 1bd3f95f1272..5614b7fe49bc 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -484,11 +484,7 @@ class Message extends Base { * .catch(console.error) */ unpin(options) { - return this.client.api - .channels(this.channel.id) - .pins(this.id) - .delete(options) - .then(() => this); + return this.channel.messages.unpin(this.id, options).then(() => this); } /** From dcd5246bcb07762c5d3228ce3d12c247e0a6171a Mon Sep 17 00:00:00 2001 From: Monbrey Date: Wed, 16 Sep 2020 10:37:31 +1000 Subject: [PATCH 06/28] feat(MessageManager): move Message#react API calls to Manager --- src/managers/MessageManager.js | 18 ++++++++++++++++++ src/structures/Message.js | 26 +++++++++----------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index 0418c1141421..6a72f49e90e7 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -1,6 +1,7 @@ 'use strict'; const BaseManager = require('./BaseManager'); +const { TypeError } = require('../errors'); const APIMessage = require('../structures/APIMessage'); const Message = require('../structures/Message'); const Collection = require('../util/Collection'); @@ -182,6 +183,23 @@ class MessageManager extends BaseManager { } } + /** + * Adds a reaction to the message, even if it's not cached. + * @param {MessageResolvable} message The messag to react to + * @param {EmojiIdentifierResolvable} emoji The emoji to react with + * @returns {Promise} + */ + async react(message, emoji) { + message = this.resolveID(message); + if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); + + emoji = this.client.emojis.resolveIdentifier(emoji); + if (!emoji) throw new TypeError('EMOJI_TYPE', 'emoji', 'EmojiIdentifierResolvable'); + + // eslint-disable-next-line newline-per-chained-call + await this.client.api.channels(this.channel.id).messages(message).reactions(emoji, '@me').put(); + } + /** * Deletes a message, even if it's not cached. * @param {MessageResolvable} message The message to delete diff --git a/src/structures/Message.js b/src/structures/Message.js index 5614b7fe49bc..50bc06c95795 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -503,23 +503,15 @@ class Message extends Base { * .catch(console.error); */ react(emoji) { - emoji = this.client.emojis.resolveIdentifier(emoji); - if (!emoji) throw new TypeError('EMOJI_TYPE'); - - return this.client.api - .channels(this.channel.id) - .messages(this.id) - .reactions(emoji, '@me') - .put() - .then( - () => - this.client.actions.MessageReactionAdd.handle({ - user: this.client.user, - channel: this.channel, - message: this, - emoji: Util.parseEmoji(emoji), - }).reaction, - ); + return this.channel.messages.react(this.id, emoji).then( + () => + this.client.actions.MessageReactionAdd.handle({ + user: this.client.user, + channel: this.channel, + message: this, + emoji: Util.parseEmoji(emoji), + }).reaction, + ); } /** From ae2ffab8abb4f8ba2f5e5e40d255a0b0150e1a3e Mon Sep 17 00:00:00 2001 From: Monbrey Date: Wed, 16 Sep 2020 10:43:19 +1000 Subject: [PATCH 07/28] fix(MessageManager): throw TypeError on non-MessageResolvable params --- src/managers/MessageManager.js | 59 +++++++++++++++++----------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index 6a72f49e90e7..270ab49d5b7d 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -123,16 +123,15 @@ class MessageManager extends BaseManager { */ async edit(message, content, options) { message = this.resolveID(message); - if (message) { - const { data } = - content instanceof APIMessage ? content.resolveData() : APIMessage.create(this, content, options).resolveData(); - await this.client.api.channels[this.channel.id].messages[message].patch({ data }).then(d => { - if (this.cache.has(message)) { - const clone = this.cache.get(message)._clone(); - clone._patch(d); - } - }); - } + if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); + const { data } = + content instanceof APIMessage ? content.resolveData() : APIMessage.create(this, content, options).resolveData(); + await this.client.api.channels[this.channel.id].messages[message].patch({ data }).then(d => { + if (this.cache.has(message)) { + const clone = this.cache.get(message)._clone(); + clone._patch(d); + } + }); } /** @@ -142,9 +141,9 @@ class MessageManager extends BaseManager { */ async crosspost(message) { message = this.resolveID(message); - if (message) { - await this.client.api.channels(this.channel.id).messages(message).crosspost.post(); - } + if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); + + await this.client.api.channels(this.channel.id).messages(message).crosspost.post(); } /** @@ -156,13 +155,13 @@ class MessageManager extends BaseManager { */ async pin(message, options) { message = this.resolveID(message); - if (message) { - await this.client.api - .channels(this.channel.id) - .pins(message) - .put(options) - .then(() => this); - } + if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); + + await this.client.api + .channels(this.channel.id) + .pins(message) + .put(options) + .then(() => this); } /** @@ -174,13 +173,13 @@ class MessageManager extends BaseManager { */ async unpin(message, options) { message = this.resolveID(message); - if (message) { - await this.client.api - .channels(this.channel.id) - .pins(message) - .delete(options) - .then(() => this); - } + if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); + + await this.client.api + .channels(this.channel.id) + .pins(message) + .delete(options) + .then(() => this); } /** @@ -208,9 +207,9 @@ class MessageManager extends BaseManager { */ async delete(message, reason) { message = this.resolveID(message); - if (message) { - await this.client.api.channels(this.channel.id).messages(message).delete({ reason }); - } + if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); + + await this.client.api.channels(this.channel.id).messages(message).delete({ reason }); } async _fetchId(messageID, cache, force) { From 85646ca5d12db7d4c279f191bf75cc9c59a95aac Mon Sep 17 00:00:00 2001 From: monbrey Date: Thu, 1 Oct 2020 07:59:59 +1000 Subject: [PATCH 08/28] chore: typings --- typings/index.d.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index c24023dfa08f..c39fd499b625 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1984,6 +1984,17 @@ declare module 'discord.js' { constructor(channel: TextChannel | DMChannel, iterable?: Iterable); public channel: TextBasedChannelFields; public cache: Collection; + public crosspost(message: MessageResolvable): Promise; + public delete(message: MessageResolvable, reason?: string): Promise; + public edit( + message: MessageResolvable, + content: APIMessageContentResolvable | MessageEditOptions | MessageEmbed | APIMessage, + ): Promise; + public edit( + message: MessageResolvable, + content: StringResolvable, + options: MessageEditOptions | MessageEmbed, + ): Promise; public fetch(message: Snowflake, cache?: boolean, force?: boolean): Promise; public fetch( options?: ChannelLogsQueryOptions, @@ -1991,7 +2002,9 @@ declare module 'discord.js' { force?: boolean, ): Promise>; public fetchPinned(cache?: boolean): Promise>; - public delete(message: MessageResolvable, reason?: string): Promise; + public react(message: MessageResolvable, emoji: EmojiIdentifierResolvable): Promise; + public pin(message: MessageResolvable, options?: { reason?: string }): Promise; + public unpin(message: MessageResolvable, options?: { reason?: string }): Promise; } // Hacky workaround because changing the signature of an overridden method errors From 1e84854abae3c990b4fd7594d70b3e325f7b6400 Mon Sep 17 00:00:00 2001 From: monbrey Date: Thu, 1 Oct 2020 09:07:54 +1000 Subject: [PATCH 09/28] fix(MessageManager): consistent API call notation Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com> --- src/managers/MessageManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index 270ab49d5b7d..08f1d662be26 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -126,7 +126,7 @@ class MessageManager extends BaseManager { if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); const { data } = content instanceof APIMessage ? content.resolveData() : APIMessage.create(this, content, options).resolveData(); - await this.client.api.channels[this.channel.id].messages[message].patch({ data }).then(d => { + await this.client.api.channels(this.channel.id).messages(message).patch({ data }).then(d => { if (this.cache.has(message)) { const clone = this.cache.get(message)._clone(); clone._patch(d); From 96570d98fbd91e2ab6b4c8976d3078d949a88723 Mon Sep 17 00:00:00 2001 From: monbrey Date: Thu, 1 Oct 2020 09:12:51 +1000 Subject: [PATCH 10/28] chore: linting --- src/managers/MessageManager.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index 08f1d662be26..eb136e509d40 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -126,12 +126,16 @@ class MessageManager extends BaseManager { if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); const { data } = content instanceof APIMessage ? content.resolveData() : APIMessage.create(this, content, options).resolveData(); - await this.client.api.channels(this.channel.id).messages(message).patch({ data }).then(d => { - if (this.cache.has(message)) { - const clone = this.cache.get(message)._clone(); - clone._patch(d); - } - }); + await this.client.api + .channels(this.channel.id) + .messages(message) + .patch({ data }) + .then(d => { + if (this.cache.has(message)) { + const clone = this.cache.get(message)._clone(); + clone._patch(d); + } + }); } /** From fbf5f3cd649c038671ea42625242d6ddbaf1eabb Mon Sep 17 00:00:00 2001 From: monbrey Date: Tue, 6 Oct 2020 08:57:31 +1100 Subject: [PATCH 11/28] fix: apply suggestions from code review Co-authored-by: izexi <43889168+izexi@users.noreply.github.com> Co-authored-by: Advaith --- src/managers/MessageManager.js | 29 +++++++++++++++++------------ src/structures/Message.js | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index eb136e509d40..ec8c746aa17e 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -119,7 +119,7 @@ class MessageManager extends BaseManager { * @param {MessageResolvable} message The message to edit * @param {StringResolvable|APIMessage} [content] The new content for the message * @param {MessageEditOptions|MessageEmbed} [options] The options to provide - * @returns {Promise} + * @returns {Promise} */ async edit(message, content, options) { message = this.resolveID(message); @@ -130,24 +130,31 @@ class MessageManager extends BaseManager { .channels(this.channel.id) .messages(message) .patch({ data }) - .then(d => { - if (this.cache.has(message)) { - const clone = this.cache.get(message)._clone(); - clone._patch(d); + .then(data => { + const existing = this.cache.get(message); + if (existing) { + const clone = existing._clone(); + clone._patch(data); + return clone; } + return data; }); } /** * Publishes a message in an announcement channel to all channels following it, even if it's not cached. * @param {MessageResolvable} message The message to publish - * @returns {Promise} + * @returns {Promise} */ async crosspost(message) { message = this.resolveID(message); if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); - await this.client.api.channels(this.channel.id).messages(message).crosspost.post(); + const data = await this.client.api + .channels(this.channel.id) + .messages(message) + .crosspost.post(); + return this.cache.get(data.id) || data; } /** @@ -164,8 +171,7 @@ class MessageManager extends BaseManager { await this.client.api .channels(this.channel.id) .pins(message) - .put(options) - .then(() => this); + .put(options); } /** @@ -182,12 +188,11 @@ class MessageManager extends BaseManager { await this.client.api .channels(this.channel.id) .pins(message) - .delete(options) - .then(() => this); + .delete(options); } /** - * Adds a reaction to the message, even if it's not cached. + * Adds a reaction to a message, even if it's not cached. * @param {MessageResolvable} message The messag to react to * @param {EmojiIdentifierResolvable} emoji The emoji to react with * @returns {Promise} diff --git a/src/structures/Message.js b/src/structures/Message.js index 040a55637c05..cc00e6c106b3 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -419,7 +419,7 @@ class Message extends Base { } /** - * Options that can be passed into Message#edit. + * Options that can be passed into {@link Message#edit}. * @typedef {Object} MessageEditOptions * @property {string} [content] Content to be edited * @property {MessageEmbed|Object} [embed] An embed to be added/edited From d712d29e13d2f3b06dbc2a3478c85078512e65c2 Mon Sep 17 00:00:00 2001 From: monbrey Date: Tue, 6 Oct 2020 09:36:59 +1100 Subject: [PATCH 12/28] fix: rename shadowed variable --- src/managers/MessageManager.js | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index ec8c746aa17e..d7b65ec16a48 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -130,14 +130,14 @@ class MessageManager extends BaseManager { .channels(this.channel.id) .messages(message) .patch({ data }) - .then(data => { + .then(d => { const existing = this.cache.get(message); if (existing) { const clone = existing._clone(); - clone._patch(data); + clone._patch(d); return clone; } - return data; + return d; }); } @@ -150,10 +150,7 @@ class MessageManager extends BaseManager { message = this.resolveID(message); if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); - const data = await this.client.api - .channels(this.channel.id) - .messages(message) - .crosspost.post(); + const data = await this.client.api.channels(this.channel.id).messages(message).crosspost.post(); return this.cache.get(data.id) || data; } @@ -168,10 +165,7 @@ class MessageManager extends BaseManager { message = this.resolveID(message); if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); - await this.client.api - .channels(this.channel.id) - .pins(message) - .put(options); + await this.client.api.channels(this.channel.id).pins(message).put(options); } /** @@ -185,10 +179,7 @@ class MessageManager extends BaseManager { message = this.resolveID(message); if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); - await this.client.api - .channels(this.channel.id) - .pins(message) - .delete(options); + await this.client.api.channels(this.channel.id).pins(message).delete(options); } /** From 4e49e04d8f2c23ec6972b605466238f3955a69e9 Mon Sep 17 00:00:00 2001 From: monbrey Date: Sat, 17 Oct 2020 10:36:19 +1100 Subject: [PATCH 13/28] feat: typings for APIRawMessage overloads --- typings/index.d.ts | 105 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 3 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 8208bf42e8a7..6b283d770872 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1982,17 +1982,27 @@ declare module 'discord.js' { constructor(channel: TextChannel | DMChannel, iterable?: Iterable); public channel: TextBasedChannelFields; public cache: Collection; - public crosspost(message: MessageResolvable): Promise; + public crosspost(message: Message): Promise; + public crosspost(message: MessageResolvable): Promise; public delete(message: MessageResolvable, reason?: string): Promise; + public edit( + message: Message, + content: APIMessageContentResolvable | MessageEditOptions | MessageEmbed | APIMessage, + ): Promise; + public edit( + message: Message, + content: StringResolvable, + options: MessageEditOptions | MessageEmbed, + ): Promise; public edit( message: MessageResolvable, content: APIMessageContentResolvable | MessageEditOptions | MessageEmbed | APIMessage, - ): Promise; + ): Promise; public edit( message: MessageResolvable, content: StringResolvable, options: MessageEditOptions | MessageEmbed, - ): Promise; + ): Promise; public fetch(message: Snowflake, cache?: boolean, force?: boolean): Promise; public fetch( options?: ChannelLogsQueryOptions, @@ -2197,6 +2207,95 @@ declare module 'discord.js' { type APIMessageContentResolvable = string | number | boolean | bigint | symbol | readonly StringResolvable[]; + interface APIRawMessage { + id: Snowflake; + type: number; + content: string; + channel_id: Snowflake; + author: { + bot?: true; + id: Snowflake; + username: string; + avatar: string | null; + discriminator: string; + }; + attachments: { + id: Snowflake; + filename: string; + size: number; + url: string; + proxy_url: string; + height: number | null; + width: number | null; + }[]; + embeds: { + title?: string; + type?: 'rich' | 'image' | 'video' | 'gifv' | 'article' | 'link'; + description?: string; + url?: string; + timestamp?: string; + color?: number; + footer?: { + text: string; + icon_url?: string; + proxy_icon_url?: string; + }; + image?: { + url?: string; + proxy_url?: string; + height?: number; + width?: number; + }; + thumbnail?: { + url?: string; + proxy_url?: string; + height?: number; + width?: number; + }; + video?: { + url?: string; + height?: number; + width?: number; + }; + provider?: { name?: string; url?: string }; + author?: { + name?: string; + url?: string; + icon_url?: string; + proxy_icon_url?: string; + }; + fields?: { + name: string; + value: string; + inline?: boolean; + }[]; + }[]; + mentions: { + id: Snowflake; + username: string; + discriminator: string; + avatar: string | null; + bot?: true; + public_flags?: number; + member?: { + nick: string | null; + roles: Snowflake[]; + joined_at: string; + premium_since?: string | null; + deaf: boolean; + mute: boolean; + }; + }[]; + mention_roles: Snowflake[]; + pinned: boolean; + mention_everyone: boolean; + tts: boolean; + timestamp: string; + edited_timestamp: string | null; + flags: number; + webhook_id: Snowflake; + } + interface ApplicationAsset { name: string; id: Snowflake; From bb22ae1f1dcc0a36fdbdf377c269ac10b5d609e6 Mon Sep 17 00:00:00 2001 From: monbrey Date: Wed, 16 Dec 2020 08:01:40 +1100 Subject: [PATCH 14/28] fix(MessageManager): return Message instance from MessageManager#edit --- src/managers/MessageManager.js | 6 +++--- src/structures/Message.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index d7b65ec16a48..b953fc7db0d8 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -119,14 +119,14 @@ class MessageManager extends BaseManager { * @param {MessageResolvable} message The message to edit * @param {StringResolvable|APIMessage} [content] The new content for the message * @param {MessageEditOptions|MessageEmbed} [options] The options to provide - * @returns {Promise} + * @returns {Promise} */ async edit(message, content, options) { message = this.resolveID(message); if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); const { data } = content instanceof APIMessage ? content.resolveData() : APIMessage.create(this, content, options).resolveData(); - await this.client.api + return this.client.api .channels(this.channel.id) .messages(message) .patch({ data }) @@ -137,7 +137,7 @@ class MessageManager extends BaseManager { clone._patch(d); return clone; } - return d; + return this.add(d); }); } diff --git a/src/structures/Message.js b/src/structures/Message.js index cc00e6c106b3..8ac462cea4f7 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -439,7 +439,7 @@ class Message extends Base { * .catch(console.error); */ edit(content, options) { - return this.channel.messages.edit(this.id, content, options).then(() => this); + return this.channel.messages.edit(this.id, content, options); } /** From 78ce3b1c944959af2ca38aaf051773cc484d0a5f Mon Sep 17 00:00:00 2001 From: monbrey Date: Wed, 16 Dec 2020 08:03:06 +1100 Subject: [PATCH 15/28] feat(MessageManager): return Message from MessageManager#crosspost --- src/managers/MessageManager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index b953fc7db0d8..488814d70dbb 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -144,14 +144,14 @@ class MessageManager extends BaseManager { /** * Publishes a message in an announcement channel to all channels following it, even if it's not cached. * @param {MessageResolvable} message The message to publish - * @returns {Promise} + * @returns {Promise} */ async crosspost(message) { message = this.resolveID(message); if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); const data = await this.client.api.channels(this.channel.id).messages(message).crosspost.post(); - return this.cache.get(data.id) || data; + return this.cache.get(data.id) || this.add(data); } /** From 609b0e048ab7beb853fae7ccbac603321c3a3e8d Mon Sep 17 00:00:00 2001 From: monbrey Date: Wed, 16 Dec 2020 08:05:54 +1100 Subject: [PATCH 16/28] fix(Message): return result of Manager call directly on crosspost --- src/structures/Message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index 8ac462cea4f7..415fbfd3772b 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -454,7 +454,7 @@ class Message extends Base { * } */ crosspost() { - return this.channel.messages.crosspost(this.id).then(() => this); + return this.channel.messages.crosspost(this.id); } /** From 149af15e40060dbdc83d8dff03a8c2977aba5225 Mon Sep 17 00:00:00 2001 From: monbrey Date: Wed, 16 Dec 2020 08:07:09 +1100 Subject: [PATCH 17/28] fix(Typings): edit and crosspost no longer return raw api messages --- typings/index.d.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 6b283d770872..aa4c0c580b74 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1983,7 +1983,6 @@ declare module 'discord.js' { public channel: TextBasedChannelFields; public cache: Collection; public crosspost(message: Message): Promise; - public crosspost(message: MessageResolvable): Promise; public delete(message: MessageResolvable, reason?: string): Promise; public edit( message: Message, @@ -1994,15 +1993,6 @@ declare module 'discord.js' { content: StringResolvable, options: MessageEditOptions | MessageEmbed, ): Promise; - public edit( - message: MessageResolvable, - content: APIMessageContentResolvable | MessageEditOptions | MessageEmbed | APIMessage, - ): Promise; - public edit( - message: MessageResolvable, - content: StringResolvable, - options: MessageEditOptions | MessageEmbed, - ): Promise; public fetch(message: Snowflake, cache?: boolean, force?: boolean): Promise; public fetch( options?: ChannelLogsQueryOptions, From 77d3019897501069fdcdb9a2ea2519210e53a2f3 Mon Sep 17 00:00:00 2001 From: "Monbrey (Ryan Munro)" Date: Mon, 28 Dec 2020 21:42:09 +1100 Subject: [PATCH 18/28] fix: linting --- src/structures/Message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index 73fe825d6879..5c4870ef1166 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -7,7 +7,7 @@ const MessageAttachment = require('./MessageAttachment'); const Embed = require('./MessageEmbed'); const Mentions = require('./MessageMentions'); const ReactionCollector = require('./ReactionCollector'); -const { Error, TypeError } = require('../errors'); +const { Error } = require('../errors'); const ReactionManager = require('../managers/ReactionManager'); const Collection = require('../util/Collection'); const { MessageTypes, SystemMessageTypes } = require('../util/Constants'); From 84365889370a1615e0301cc57db887fede1c424c Mon Sep 17 00:00:00 2001 From: "Monbrey (Ryan Munro)" Date: Mon, 28 Dec 2020 21:52:49 +1100 Subject: [PATCH 19/28] fix: tslint --- typings/index.d.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 15d197095a1f..082847966077 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1978,15 +1978,11 @@ declare module 'discord.js' { public channel: TextBasedChannelFields; public cache: Collection; public crosspost(message: Message): Promise; - public delete(message: MessageResolvable, reason?: string): Promise; - public edit( - message: Message, - content: APIMessageContentResolvable | MessageEditOptions | MessageEmbed | APIMessage, - ): Promise; + public delete(message: MessageResolvable): Promise; public edit( - message: Message, - content: StringResolvable, - options: MessageEditOptions | MessageEmbed, + ...args: + | [message: Message, content: APIMessageContentResolvable | MessageEditOptions | MessageEmbed | APIMessage] + | [message: Message, content: StringResolvable, options: MessageEditOptions | MessageEmbed] ): Promise; public fetch(message: Snowflake, cache?: boolean, force?: boolean): Promise; public fetch( @@ -1998,7 +1994,6 @@ declare module 'discord.js' { public react(message: MessageResolvable, emoji: EmojiIdentifierResolvable): Promise; public pin(message: MessageResolvable, options?: { reason?: string }): Promise; public unpin(message: MessageResolvable, options?: { reason?: string }): Promise; - public delete(message: MessageResolvable): Promise; } // Hacky workaround because changing the signature of an overridden method errors From 64b77d71f571bc4452b2326f9e10d101fad49d4f Mon Sep 17 00:00:00 2001 From: "Monbrey (Ryan Munro)" Date: Fri, 5 Feb 2021 07:37:37 +1100 Subject: [PATCH 20/28] feat: return Message from MessageManager#edit --- src/managers/MessageManager.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index fa71fde858ae..6bf3501b9417 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -121,24 +121,20 @@ class MessageManager extends BaseManager { * @param {MessageEditOptions|MessageEmbed} [options] The options to provide * @returns {Promise} */ - async edit(message, content, options) { + edit(message, content, options) { message = this.resolveID(message); if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); + const { data } = content instanceof APIMessage ? content.resolveData() : APIMessage.create(this, content, options).resolveData(); - return this.client.api - .channels(this.channel.id) - .messages(message) - .patch({ data }) - .then(d => { - const existing = this.cache.get(message); - if (existing) { - const clone = existing._clone(); - clone._patch(d); - return clone; - } - return this.add(d); - }); + return this.client.api.channels[this.channel.id].messages[message].patch({ data }).then(d => { + if (this.cache.has(message)) { + const clone = this.cache.get(message)._clone(); + clone._patch(d); + return clone; + } + return this.channel.messages.add(d); + }); } /** From 7bf12fbb2ece4effe55dd183dc3f5ae539b11326 Mon Sep 17 00:00:00 2001 From: "Monbrey (Ryan Munro)" Date: Fri, 5 Feb 2021 07:40:52 +1100 Subject: [PATCH 21/28] fix: suggestions --- src/managers/MessageManager.js | 18 +++++++++--------- typings/index.d.ts | 9 ++++++--- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index 6bf3501b9417..58985e1e21d3 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -121,20 +121,20 @@ class MessageManager extends BaseManager { * @param {MessageEditOptions|MessageEmbed} [options] The options to provide * @returns {Promise} */ - edit(message, content, options) { + async edit(message, content, options) { message = this.resolveID(message); if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); const { data } = content instanceof APIMessage ? content.resolveData() : APIMessage.create(this, content, options).resolveData(); - return this.client.api.channels[this.channel.id].messages[message].patch({ data }).then(d => { - if (this.cache.has(message)) { - const clone = this.cache.get(message)._clone(); - clone._patch(d); - return clone; - } - return this.channel.messages.add(d); - }); + const d = await this.client.api.channels[this.channel.id].messages[message].patch({ data }); + + if (this.cache.has(message)) { + const clone = this.cache.get(message)._clone(); + clone._patch(d); + return clone; + } + return this.add(d); } /** diff --git a/typings/index.d.ts b/typings/index.d.ts index 082847966077..3c9a68c61e73 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1977,12 +1977,15 @@ declare module 'discord.js' { constructor(channel: TextChannel | DMChannel, iterable?: Iterable); public channel: TextBasedChannelFields; public cache: Collection; - public crosspost(message: Message): Promise; + public crosspost(message: MessageResolvable): Promise; public delete(message: MessageResolvable): Promise; public edit( ...args: - | [message: Message, content: APIMessageContentResolvable | MessageEditOptions | MessageEmbed | APIMessage] - | [message: Message, content: StringResolvable, options: MessageEditOptions | MessageEmbed] + | [ + message: MessageResolvable, + content: APIMessageContentResolvable | MessageEditOptions | MessageEmbed | APIMessage, + ] + | [message: MessageResolvable, content: StringResolvable, options: MessageEditOptions | MessageEmbed] ): Promise; public fetch(message: Snowflake, cache?: boolean, force?: boolean): Promise; public fetch( From 6793fe5bf4788bac40408fbec752a1264e00fcef Mon Sep 17 00:00:00 2001 From: "Monbrey (Ryan Munro)" Date: Mon, 15 Feb 2021 10:39:05 +1100 Subject: [PATCH 22/28] fix: remove unused interface --- typings/index.d.ts | 89 ---------------------------------------------- 1 file changed, 89 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 3c9a68c61e73..6ea80d049ae7 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2211,95 +2211,6 @@ declare module 'discord.js' { type APIMessageContentResolvable = string | number | boolean | bigint | symbol | readonly StringResolvable[]; - interface APIRawMessage { - id: Snowflake; - type: number; - content: string; - channel_id: Snowflake; - author: { - bot?: true; - id: Snowflake; - username: string; - avatar: string | null; - discriminator: string; - }; - attachments: { - id: Snowflake; - filename: string; - size: number; - url: string; - proxy_url: string; - height: number | null; - width: number | null; - }[]; - embeds: { - title?: string; - type?: 'rich' | 'image' | 'video' | 'gifv' | 'article' | 'link'; - description?: string; - url?: string; - timestamp?: string; - color?: number; - footer?: { - text: string; - icon_url?: string; - proxy_icon_url?: string; - }; - image?: { - url?: string; - proxy_url?: string; - height?: number; - width?: number; - }; - thumbnail?: { - url?: string; - proxy_url?: string; - height?: number; - width?: number; - }; - video?: { - url?: string; - height?: number; - width?: number; - }; - provider?: { name?: string; url?: string }; - author?: { - name?: string; - url?: string; - icon_url?: string; - proxy_icon_url?: string; - }; - fields?: { - name: string; - value: string; - inline?: boolean; - }[]; - }[]; - mentions: { - id: Snowflake; - username: string; - discriminator: string; - avatar: string | null; - bot?: true; - public_flags?: number; - member?: { - nick: string | null; - roles: Snowflake[]; - joined_at: string; - premium_since?: string | null; - deaf: boolean; - mute: boolean; - }; - }[]; - mention_roles: Snowflake[]; - pinned: boolean; - mention_everyone: boolean; - tts: boolean; - timestamp: string; - edited_timestamp: string | null; - flags: number; - webhook_id: Snowflake; - } - interface ApplicationAsset { name: string; id: Snowflake; From 0d490343942c5a490fca4778a20cec5760bf1580 Mon Sep 17 00:00:00 2001 From: Monbrey Date: Fri, 30 Apr 2021 23:01:12 +1000 Subject: [PATCH 23/28] fix(Typings): convert MessageManager#edit to overloads --- typings/index.d.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 6ea80d049ae7..e2fa1035665b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1980,12 +1980,13 @@ declare module 'discord.js' { public crosspost(message: MessageResolvable): Promise; public delete(message: MessageResolvable): Promise; public edit( - ...args: - | [ - message: MessageResolvable, - content: APIMessageContentResolvable | MessageEditOptions | MessageEmbed | APIMessage, - ] - | [message: MessageResolvable, content: StringResolvable, options: MessageEditOptions | MessageEmbed] + message: MessageResolvable, + content: APIMessageContentResolvable | MessageEditOptions | MessageEmbed | APIMessage, + ): Promise; + public edit( + message: MessageResolvable, + content: StringResolvable, + options: MessageEditOptions | MessageEmbed, ): Promise; public fetch(message: Snowflake, cache?: boolean, force?: boolean): Promise; public fetch( From 667895d55038736bd634fdcc2790ed27bdd7f2c0 Mon Sep 17 00:00:00 2001 From: Monbrey Date: Fri, 30 Apr 2021 23:01:36 +1000 Subject: [PATCH 24/28] fix(Message): use async/await --- src/structures/Message.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index 5c4870ef1166..9885c7e8823b 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -543,16 +543,14 @@ class Message extends Base { * .then(console.log) * .catch(console.error); */ - react(emoji) { - return this.channel.messages.react(this.id, emoji).then( - () => - this.client.actions.MessageReactionAdd.handle({ - user: this.client.user, - channel: this.channel, - message: this, - emoji: Util.parseEmoji(emoji), - }).reaction, - ); + async react(emoji) { + await this.channel.messages.react(this.id, emoji); + return this.client.actions.MessageReactionAdd.handle({ + user: this.client.user, + channel: this.channel, + message: this, + emoji: Util.parseEmoji(emoji), + }).reaction; } /** From 85b8fa6c5652c317c59973d3cdc1b5f6c7b9de42 Mon Sep 17 00:00:00 2001 From: Monbrey Date: Mon, 3 May 2021 07:31:51 +1000 Subject: [PATCH 25/28] fix: drop unsupported options.reason --- src/managers/MessageManager.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index 58985e1e21d3..b49ea8dd50ea 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -153,29 +153,25 @@ class MessageManager extends BaseManager { /** * Pins a message to the channel's pinned messages, even if it's not cached. * @param {MessageResolvable} message The message to pin - * @param {Object} [options] Options for pinning - * @param {string} [options.reason] Reason for pinning * @returns {Promise} */ - async pin(message, options) { + async pin(message) { message = this.resolveID(message); if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); - await this.client.api.channels(this.channel.id).pins(message).put(options); + await this.client.api.channels(this.channel.id).pins(message).put(); } /** * Unins a message from the channel's pinned messages, even if it's not cached. * @param {MessageResolvable} message The message to unpin - * @param {Object} [options] Options for unpinning - * @param {string} [options.reason] Reason for unpinning * @returns {Promise} */ - async unpin(message, options) { + async unpin(message) { message = this.resolveID(message); if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); - await this.client.api.channels(this.channel.id).pins(message).delete(options); + await this.client.api.channels(this.channel.id).pins(message).delete(); } /** From c7cfd6e22f959b34df7877b79c6f73055c86fa9f Mon Sep 17 00:00:00 2001 From: Monbrey Date: Mon, 3 May 2021 07:43:55 +1000 Subject: [PATCH 26/28] fix(Message): remove unsupport options.reason from pin/unpin --- src/structures/Message.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index 0527c2775372..1546486fdf4f 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -488,32 +488,28 @@ 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' }) + * // Pin a message + * message.pin() * .then(console.log) * .catch(console.error) */ - pin(options) { - return this.channel.messages.pin(this.id, options).then(() => this); + pin() { + return this.channel.messages.pin(this.id).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' }) + * // Unpin a message + * message.unpin() * .then(console.log) * .catch(console.error) */ - unpin(options) { - return this.channel.messages.unpin(this.id, options).then(() => this); + unpin() { + return this.channel.messages.unpin(this.id).then(() => this); } /** From 6fc2592b1329889e6dff8d401c201a620eb2c4a0 Mon Sep 17 00:00:00 2001 From: Monbrey Date: Mon, 3 May 2021 07:49:22 +1000 Subject: [PATCH 27/28] fix: typings --- typings/index.d.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 157929797dc8..d112ba64d311 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1048,7 +1048,7 @@ declare module 'discord.js' { public fetchWebhook(): Promise; public crosspost(): Promise; public fetch(force?: boolean): Promise; - public pin(options?: { reason?: string }): Promise; + public pin(): Promise; public react(emoji: EmojiIdentifierResolvable): Promise; public reply( content: APIMessageContentResolvable | (MessageOptions & { split?: false }) | MessageAdditions, @@ -1067,7 +1067,7 @@ declare module 'discord.js' { public suppressEmbeds(suppress?: boolean): Promise; public toJSON(): object; public toString(): string; - public unpin(options?: { reason?: string }): Promise; + public unpin(): Promise; } export class MessageAttachment { @@ -1378,7 +1378,7 @@ declare module 'discord.js' { public eval(fn: (client: Client) => T): Promise; public fetchClientValue(prop: string): Promise; public kill(): void; - public respawn(options?: { delay?: number, timeout?: number }): Promise; + public respawn(options?: { delay?: number; timeout?: number }): Promise; public send(message: any): Promise; public spawn(timeout?: number): Promise; @@ -1411,7 +1411,7 @@ declare module 'discord.js' { public broadcastEval(fn: (client: Client) => T, shard: number): Promise; public fetchClientValues(prop: string): Promise; public fetchClientValues(prop: string, shard: number): Promise; - public respawnAll(options?: { shardDelay?: number, respawnDelay?: number, timeout?: number }): Promise; + public respawnAll(options?: { shardDelay?: number; respawnDelay?: number; timeout?: number }): Promise; public send(message: any): Promise; public static singleton(client: Client, mode: ShardingManagerMode): ShardClientUtil; @@ -1448,11 +1448,15 @@ declare module 'discord.js' { public fetchClientValues(prop: string): Promise; public fetchClientValues(prop: string, shard: number): Promise; public respawnAll(options?: { - shardDelay?: number, - respawnDelay?: number, - timeout?: number, + shardDelay?: number; + respawnDelay?: number; + timeout?: number; + }): Promise>; + public spawn(options?: { + amount?: number | 'auto'; + delay?: number; + timeout?: number; }): Promise>; - public spawn(options?: { amount?: number | 'auto', delay?: number, timeout?: number }): Promise>; public on(event: 'shardCreate', listener: (shard: Shard) => void): this; @@ -2080,8 +2084,8 @@ declare module 'discord.js' { ): Promise>; public fetchPinned(cache?: boolean): Promise>; public react(message: MessageResolvable, emoji: EmojiIdentifierResolvable): Promise; - public pin(message: MessageResolvable, options?: { reason?: string }): Promise; - public unpin(message: MessageResolvable, options?: { reason?: string }): Promise; + public pin(message: MessageResolvable): Promise; + public unpin(message: MessageResolvable): Promise; } export class PresenceManager extends BaseManager { From 3946c8b0069d41be07aa8cb05ad9cfd95fcb8e2b Mon Sep 17 00:00:00 2001 From: Monbrey Date: Tue, 11 May 2021 08:24:15 +1000 Subject: [PATCH 28/28] chore: change MessageManager#edit to accept a single options object --- src/managers/MessageManager.js | 8 +++----- src/structures/Message.js | 6 +++++- typings/index.d.ts | 10 +--------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index b49ea8dd50ea..d889695ea415 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -117,16 +117,14 @@ class MessageManager extends BaseManager { /** * Edits a message, even if it's not cached. * @param {MessageResolvable} message The message to edit - * @param {StringResolvable|APIMessage} [content] The new content for the message - * @param {MessageEditOptions|MessageEmbed} [options] The options to provide + * @param {MessageEditOptions} [options] The options to provide * @returns {Promise} */ - async edit(message, content, options) { + async edit(message, options) { message = this.resolveID(message); if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable'); - const { data } = - content instanceof APIMessage ? content.resolveData() : APIMessage.create(this, content, options).resolveData(); + const { data } = APIMessage.create(this, options).resolveData(); const d = await this.client.api.channels[this.channel.id].messages[message].patch({ data }); if (this.cache.has(message)) { diff --git a/src/structures/Message.js b/src/structures/Message.js index 1546486fdf4f..e046f43b2614 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -468,7 +468,11 @@ class Message extends Base { * .catch(console.error); */ edit(content, options) { - return this.channel.messages.edit(this.id, content, options); + if (!options && typeof content === 'object' && !Array.isArray(content)) { + options = content; + content = undefined; + } + return this.channel.messages.edit(this.id, { content, ...options }); } /** diff --git a/typings/index.d.ts b/typings/index.d.ts index d112ba64d311..3ba3770f902c 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2067,15 +2067,7 @@ declare module 'discord.js' { public cache: Collection; public crosspost(message: MessageResolvable): Promise; public delete(message: MessageResolvable): Promise; - public edit( - message: MessageResolvable, - content: APIMessageContentResolvable | MessageEditOptions | MessageEmbed | APIMessage, - ): Promise; - public edit( - message: MessageResolvable, - content: StringResolvable, - options: MessageEditOptions | MessageEmbed, - ): Promise; + public edit(message: MessageResolvable, options: MessageEditOptions): Promise; public fetch(message: Snowflake, cache?: boolean, force?: boolean): Promise; public fetch( options?: ChannelLogsQueryOptions,