fix: Fetch message from NSFW Channel

fix #203
This commit is contained in:
March 7th 2022-07-15 21:35:23 +07:00
parent a1c8093181
commit 93d875c237
2 changed files with 6 additions and 1 deletions

View File

@ -228,6 +228,7 @@ class MessageManager extends CachedManager {
channel_id: this.channel.id, channel_id: this.channel.id,
max_id: new BigNumber.BigNumber(messageId).plus(1).toString(), max_id: new BigNumber.BigNumber(messageId).plus(1).toString(),
min_id: new BigNumber.BigNumber(messageId).minus(1).toString(), min_id: new BigNumber.BigNumber(messageId).minus(1).toString(),
include_nsfw: true,
}, },
}) })
).messages[0]; ).messages[0];
@ -252,6 +253,7 @@ class MessageManager extends CachedManager {
* @property {Array<Snowflake>} [channel] An array of channel IDs to filter by * @property {Array<Snowflake>} [channel] An array of channel IDs to filter by
* @property {boolean} [pinned] Whether to filter by pinned messages * @property {boolean} [pinned] Whether to filter by pinned messages
* @property {Array<string>} [has] Message has: `link`, `embed`, `file`, `video`, `image`, or `sound` * @property {Array<string>} [has] Message has: `link`, `embed`, `file`, `video`, `image`, or `sound`
* @property {boolean} [nsfw=false] Whether to filter by NSFW channels
*/ */
/** /**
@ -266,7 +268,7 @@ class MessageManager extends CachedManager {
* @returns {MessageSearchResult} * @returns {MessageSearchResult}
*/ */
async search(options = {}) { async search(options = {}) {
let { author, content, mentions, has, maxId, minId, channelId, pinned } = Object.assign( let { author, content, mentions, has, maxId, minId, channelId, pinned, nsfw } = Object.assign(
{ {
author: [], author: [],
content: '', content: '',
@ -276,6 +278,7 @@ class MessageManager extends CachedManager {
minId: null, minId: null,
channelId: [], channelId: [],
pinned: false, pinned: false,
nsfw: false,
}, },
options, options,
); );
@ -289,6 +292,7 @@ class MessageManager extends CachedManager {
if (has.length > 0) stringQuery.push(has.map(v => `has=${v}`).join('&')); if (has.length > 0) stringQuery.push(has.map(v => `has=${v}`).join('&'));
if (maxId) stringQuery.push(`max_id=${maxId}`); if (maxId) stringQuery.push(`max_id=${maxId}`);
if (minId) stringQuery.push(`min_id=${minId}`); if (minId) stringQuery.push(`min_id=${minId}`);
if (nsfw) stringQuery.push('include_nsfw=true');
if (this.channel.guildId && channelId.length > 0) { if (this.channel.guildId && channelId.length > 0) {
stringQuery.push(channelId.map(id => `channel_id=${id}`).join('&')); stringQuery.push(channelId.map(id => `channel_id=${id}`).join('&'));
} }

1
typings/index.d.ts vendored
View File

@ -3781,6 +3781,7 @@ export interface MessageSearchOptions {
minId: Snowflake; minId: Snowflake;
channelId: Snowflake[]; channelId: Snowflake[];
pinned: boolean; pinned: boolean;
nsfw: boolean;
} }
export interface MessageSearchResult { export interface MessageSearchResult {