From 64ce829ab2705e987beb72a9823d31b981775d73 Mon Sep 17 00:00:00 2001 From: Pg Biel Date: Tue, 21 Mar 2017 02:42:39 -0300 Subject: [PATCH] Make FetchMessage work for non-bot users (#1291) * [WIP] make fetchMessage work for normal users wip * Actual thing * not WIP anymore better docs * oops * better stuff * Update TextBasedChannel.js * Update TextBasedChannel.js * Update TextBasedChannel.js --- src/structures/interface/TextBasedChannel.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/structures/interface/TextBasedChannel.js b/src/structures/interface/TextBasedChannel.js index 2901835c3..0a0161c9b 100644 --- a/src/structures/interface/TextBasedChannel.js +++ b/src/structures/interface/TextBasedChannel.js @@ -181,7 +181,8 @@ class TextBasedChannel { /** * Gets a single message from this channel, regardless of it being cached or not. - * This is only available when using a bot account. + * Since the single message fetching endpoint is reserved for bot accounts, this abstracts + * {@link #fetchMessages} to obtain the single message when using a user account. * @param {Snowflake} messageID ID of the message to get * @returns {Promise} * @example @@ -191,6 +192,13 @@ class TextBasedChannel { * .catch(console.error); */ fetchMessage(messageID) { + if (!this.client.user.bot) { + return this.fetchMessages({ limit: 1, around: messageID }).then(messages => { + const msg = messages.first(); + if (msg.id !== messageID) throw new Error('Message not found.'); + return msg; + }); + } return this.client.rest.methods.getChannelMessage(this, messageID).then(data => { const msg = data instanceof Message ? data : new Message(this, data, this.client); this._cacheMessage(msg);