Messages Fetch Fix

Not using endpoint messages,
using search endpoint
This commit is contained in:
March 7th 2022-03-26 23:00:07 +07:00
parent 52e63f117f
commit 91b5be5a88
2 changed files with 25 additions and 11 deletions

View File

@ -2,10 +2,11 @@
const { Collection } = require('@discordjs/collection');
const CachedManager = require('./CachedManager');
const { TypeError } = require('../errors');
const { TypeError, Error } = require('../errors');
const { Message } = require('../structures/Message');
const MessagePayload = require('../structures/MessagePayload');
const Util = require('../util/Util');
const BigNumber = require('bignumber.js');
/**
* Manages API methods for Messages and holds their cache.
@ -216,8 +217,19 @@ class MessageManager extends CachedManager {
if (existing && !existing.partial) return existing;
}
const data = await this.client.api.channels[this.channel.id].messages[messageId].get();
return this._add(data, cache);
// const data = await this.client.api.channels[this.channel.id].messages[messageId].get(); // Discord Block
// https://canary.discord.com/api/v9/guilds/809133733591384155/messages/search?channel_id=840225732902518825&max_id=957254525360697375&min_id=957254525360697373
const data = (
await this.client.api.guilds[this.channel.guild.id].messages.search.get({
query: {
channel_id: this.channel.id,
max_id: new BigNumber.BigNumber(messageId).plus(1).toString(),
min_id: new BigNumber.BigNumber(messageId).minus(1).toString(),
},
})
).messages[0]
if (data) return this._add(data[0], cache);
else throw new Error('MESSAGE_ID_NOT_FOUND');
}
async _fetchMany(options = {}, cache) {

View File

@ -211,14 +211,16 @@ class Message extends Base {
* All valid mentions that the message contains
* @type {MessageMentions}
*/
this.mentions = new Mentions(
this,
data.mentions,
data.mention_roles,
data.mention_everyone,
data.mention_channels,
data.referenced_message?.author,
);
if (!data.mentions)
this.mentions = new Mentions(
this,
data.mentions,
data.mention_roles,
data.mention_everyone,
data.mention_channels,
data.referenced_message?.author,
);
else data.mentions instanceof Mentions ? this.mentions = data.mentions : this.mentions = null;
} else {
this.mentions = new Mentions(
this,