From 9bab1f1983bff126c6c2ebb8e7790564b816818f Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Mon, 6 Feb 2023 19:37:11 +0700 Subject: [PATCH] fix: `can't get the reactions of a message` #517 - new api --- src/managers/MessageManager.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index 4390dd0..5c004c9 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -234,12 +234,14 @@ class MessageManager extends CachedManager { await this.client.api.channels(this.channel.id).messages(message).delete(); } - async _fetchId(messageId, cache, force) { + _fetchId(messageId, cache, force) { if (!force) { const existing = this.cache.get(messageId); if (existing && !existing.partial) return existing; } + // Search API + /* if (this.channel.guildId) { const data = ( await this.client.api.guilds[this.channel.guild.id].messages.search.get({ @@ -265,6 +267,20 @@ class MessageManager extends CachedManager { if (data) return this._add(data[0], cache); else throw new Error('MESSAGE_ID_NOT_FOUND'); } + */ + + // Get API + // https://discord.com/api/v9/channels/:id/messages?limit=50&around=:msgid + return new Promise((resolve, reject) => { + this._fetchMany({ + around: messageId, + limit: 50, + }) + .then(data_ => + data_.has(messageId) ? resolve(data_.get(messageId)) : reject(new Error('MESSAGE_ID_NOT_FOUND')), + ) + .catch(reject); + }); } async _fetchMany(options = {}, cache) {