fix(MessageManager): fetch error (DMs channel)

fixed #239
This commit is contained in:
March 7th 2022-08-06 22:07:41 +07:00
parent c794e9ac6b
commit 47104f8118

View File

@ -220,8 +220,7 @@ class MessageManager extends CachedManager {
if (existing && !existing.partial) return existing;
}
// 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
if (this.channel.guildId) {
const data = (
await this.client.api.guilds[this.channel.guild.id].messages.search.get({
query: {
@ -234,6 +233,18 @@ class MessageManager extends CachedManager {
).messages[0];
if (data) return this._add(data[0], cache);
else throw new Error('MESSAGE_ID_NOT_FOUND');
} else {
const data = (
await this.client.api.channels[this.channel.id].messages.search.get({
query: {
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) {
@ -286,7 +297,7 @@ class MessageManager extends CachedManager {
},
options,
);
const stringQuery = [];
let stringQuery = [];
const result = new Collection();
let data;
if (author.length > 0) stringQuery.push(author.map(id => `author_id=${id}`).join('&'));
@ -313,6 +324,7 @@ class MessageManager extends CachedManager {
if (this.channel.guildId) {
data = await this.client.api.guilds[this.channel.guildId].messages[`search?${stringQuery.join('&')}`].get();
} else {
stringQuery = stringQuery.filter(v => !v.startsWith('channel_id') && !v.startsWith('include_nsfw'));
data = await this.client.api.channels[this.channel.id].messages[`search?${stringQuery.join('&')}`].get();
}
for await (const message of data.messages) result.set(message[0].id, new Message(this.client, message[0]));