feat(MessageMethods#list): implements /channels/{channel.id}/messages for getting bulk messages (#297)

* feat(Formatter#generateOAuth2URL): addition of a new method for creating discord oauth2 links

* feat(MessageMethods#list): implements /channels/{channel.id}/messages for getting bulk messages
This commit is contained in:
Xeno 2024-11-17 00:12:34 +05:30 committed by GitHub
parent 3e14166247
commit d6a305a371
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View File

@ -1,13 +1,14 @@
import { resolveFiles } from '../../builders';
import { MessagesMethods } from '../../structures';
import type {
RESTGetAPIChannelMessagesQuery,
RESTPatchAPIChannelMessageJSONBody,
RESTPostAPIChannelMessageJSONBody,
RESTPostAPIChannelMessagesThreadsJSONBody,
} from '../../types';
import type { ValidAnswerId } from '../../api/Routes/channels';
import { Transformers } from '../../client/transformers';
import { Transformers } from '../../client';
import type { MessageCreateBodyRequest, MessageUpdateBodyRequest } from '../types/write';
import { BaseShorter } from './base';
@ -111,4 +112,11 @@ export class MessageShorter extends BaseShorter {
.get()
.then(data => data.users.map(user => Transformers.User(this.client, user)));
}
list(channelId: string, fetchOptions: RESTGetAPIChannelMessagesQuery) {
return this.client.proxy
.channels(channelId)
.messages.get({ query: fetchOptions })
.then(messages => messages.map(message => Transformers.Message(this.client, message)));
}
}

View File

@ -15,7 +15,7 @@ import {
type ThreadChannelStructure,
Transformers,
type VoiceChannelStructure,
} from '../client/transformers';
} from '../client';
import type { UsingClient } from '../commands';
import type {
EmojiResolvable,
@ -45,6 +45,7 @@ import {
ChannelType,
type RESTAPIAttachment,
type RESTGetAPIChannelMessageReactionUsersQuery,
type RESTGetAPIChannelMessagesQuery,
type RESTPatchAPIChannelJSONBody,
type RESTPatchAPIGuildChannelPositionsJSONBody,
type RESTPostAPIChannelWebhookJSONBody,
@ -253,6 +254,7 @@ export class MessagesMethods extends DiscordBase {
delete: (messageId: string, reason?: string) => ctx.client.messages.delete(messageId, ctx.channelId, reason),
fetch: (messageId: string) => ctx.client.messages.fetch(messageId, ctx.channelId),
purge: (messages: string[], reason?: string) => ctx.client.messages.purge(messages, ctx.channelId, reason),
list: (fetchOptions: RESTGetAPIChannelMessagesQuery) => ctx.client.messages.list(ctx.channelId, fetchOptions),
};
}
@ -406,8 +408,7 @@ export class VoiceChannelMethods extends DiscordBase {
if (!this.guildId) return [];
const states = await this.cache.voiceStates?.values(this.guildId);
if (!states?.length) return [];
const filter = states.filter(state => state.channelId === this.id);
return filter;
return states.filter(state => state.channelId === this.id);
}
public async members(force?: boolean) {