fix: clean code & messages cache

This commit is contained in:
MARCROCK22 2024-04-22 18:27:36 -04:00
parent a60bd19937
commit ef0786775c
5 changed files with 20 additions and 131 deletions

View File

@ -61,19 +61,15 @@ import type { RestArguments } from '../api';
export interface ChannelRoutes {
channels(id: string): {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIChannelResult>;
//.
patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIChannelJSONBody>,
): Promise<RESTPatchAPIChannelResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIChannelResult>;
users: (id: '@me') => {
threads: {
archived: {
private: {
//.
get(
args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIChannelThreadsArchivedQuery>,
): Promise<RESTGetAPIChannelUsersThreadsArchivedResult>;
@ -82,33 +78,26 @@ export interface ChannelRoutes {
};
};
'thread-members': {
//.
get(
args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIChannelThreadMembersQuery>,
): Promise<RESTGetAPIChannelThreadMembersResult>;
(
id: '@me',
): {
//.
put(args?: RestArguments<ProxyRequestMethod.Put>): Promise<RESTPutAPIChannelThreadMembersResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIChannelThreadMembersResult>;
};
(
id: string,
): {
//.
get(
args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIChannelThreadMemberQuery>,
): Promise<RESTGetAPIChannelThreadMemberResult>;
//.
put(args?: RestArguments<ProxyRequestMethod.Put>): Promise<RESTPutAPIChannelThreadMembersResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIChannelThreadMembersResult>;
};
};
threads: {
//.
post(
args: RestArguments<
ProxyRequestMethod.Post,
@ -117,13 +106,11 @@ export interface ChannelRoutes {
): Promise<RESTPostAPIChannelThreadsResult>;
archived: {
public: {
//.
get(
args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIChannelThreadsArchivedQuery>,
): Promise<RESTGetAPIChannelThreadsArchivedPublicResult>;
};
private: {
//.
get(
args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIChannelThreadsArchivedQuery>,
): Promise<RESTGetAPIChannelThreadsArchivedPrivateResult>;
@ -131,58 +118,45 @@ export interface ChannelRoutes {
};
};
recipients: (id: string) => {
//.
put(
args?: RestArguments<ProxyRequestMethod.Put, RESTPutAPIChannelRecipientJSONBody>,
): Promise<RESTPutAPIChannelRecipientResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIChannelRecipientResult>;
};
pins: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIChannelPinsResult>;
(
id: string,
): {
//.
put(args?: RestArguments<ProxyRequestMethod.Put>): Promise<RESTPutAPIChannelPinResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIChannelPinResult>;
};
};
followers: {
//.
post(
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIChannelFollowersJSONBody>,
): Promise<RESTPostAPIChannelFollowersResult>;
};
permissions: (id: string) => {
//.
put(
args?: RestArguments<ProxyRequestMethod.Put, RESTPutAPIChannelPermissionJSONBody>,
): Promise<RESTPutAPIChannelPermissionResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIChannelPermissionResult>;
};
invites: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIChannelInvitesResult>;
//.
post(
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIChannelInviteJSONBody>,
): Promise<RESTPostAPIChannelInviteResult>;
};
messages: {
//.
get(
args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIChannelMessagesQuery>,
): Promise<RESTGetAPIChannelMessagesResult>;
//.
post(
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIChannelMessageJSONBody>,
): Promise<RESTPostAPIChannelMessageResult>;
'bulk-delete': {
//.
post(
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIChannelMessagesBulkDeleteJSONBody>,
): Promise<RESTPostAPIChannelMessagesBulkDeleteResult>;
@ -190,44 +164,34 @@ export interface ChannelRoutes {
(
id: string,
): {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIChannelMessageResult>;
//.
patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIChannelMessageJSONBody>,
): Promise<RESTPatchAPIChannelMessageResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIChannelMessageResult>;
threads: {
//.
post(
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIChannelMessagesThreadsJSONBody>,
): Promise<RESTPostAPIChannelMessagesThreadsResult>;
};
crosspost: {
//.
post(args: RestArguments<ProxyRequestMethod.Post>): Promise<RESTPostAPIChannelMessageCrosspostResult>;
};
reactions: {
//.
delete(
args?: RestArguments<ProxyRequestMethod.Delete>,
): Promise<RESTDeleteAPIChannelAllMessageReactionsResult>;
(
emoji: string,
): {
//.
get(
args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIChannelMessageReactionUsersQuery>,
): Promise<RESTGetAPIChannelMessageReactionUsersResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIChannelMessageReactionResult>;
(
id: '@me',
): {
//.
put(args?: RestArguments<ProxyRequestMethod.Put>): Promise<RESTPutAPIChannelMessageReactionResult>;
//.
delete(
args?: RestArguments<ProxyRequestMethod.Delete>,
): Promise<RESTDeleteAPIChannelMessageReactionResult>;
@ -235,7 +199,6 @@ export interface ChannelRoutes {
(
id: string,
): {
//.
delete(
args?: RestArguments<ProxyRequestMethod.Delete>,
): Promise<RESTDeleteAPIChannelMessageReactionResult>;
@ -245,13 +208,10 @@ export interface ChannelRoutes {
};
};
typing: {
//.
post(args?: RestArguments<ProxyRequestMethod.Post>): Promise<RESTPostAPIChannelTypingResult>;
};
webhooks: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildWebhooksResult>;
//.
post(
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIChannelWebhookJSONBody>,
): Promise<RESTPostAPIChannelWebhookResult>;

View File

@ -118,12 +118,9 @@ import type { RawFile } from '../shared';
export interface GuildRoutes {
guilds: {
//.
post(args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIGuildsJSONBody>): Promise<RESTPostAPIGuildsResult>;
templates(code: string): {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPITemplateResult>;
//.
post(
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPITemplateCreateGuildJSONBody>,
): Promise<RESTPostAPITemplateCreateGuildResult>;
@ -131,71 +128,54 @@ export interface GuildRoutes {
(
id: string,
): {
//.
get(args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIGuildQuery>): Promise<RESTGetAPIGuildResult>;
//.
patch(args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildJSONBody>): Promise<RESTPatchAPIGuildResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIGuildResult>;
webhooks: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildWebhooksResult>;
};
preview: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildPreviewResult>;
};
'audit-logs': {
//.
get(args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIAuditLogQuery>): Promise<RESTGetAPIAuditLogResult>;
};
'auto-moderation': {
rules: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIAutoModerationRulesResult>;
//.
post(
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIAutoModerationRuleJSONBody>,
): Promise<RESTPostAPIAutoModerationRuleResult>;
(
id: string,
): {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIAutoModerationRuleResult>;
//.
patch(
args: RestArguments<ProxyRequestMethod.Post, RESTPatchAPIAutoModerationRuleJSONBody>,
): Promise<RESTPatchAPIAutoModerationRuleResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIAutoModerationRuleResult>;
};
};
};
channels: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildChannelsResult>;
//.
post(
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIGuildChannelJSONBody>,
): Promise<RESTPostAPIGuildChannelResult>;
//.
patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildChannelPositionsJSONBody>,
): Promise<RESTPatchAPIGuildChannelPositionsResult>;
};
members: {
//.
get(
args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIGuildMembersQuery>,
): Promise<RESTGetAPIGuildMembersResult>;
search: {
//.
get(
args: RestArguments<ProxyRequestMethod.Get, RESTGetAPIGuildMembersSearchQuery>,
): Promise<RESTGetAPIGuildMembersSearchResult>;
};
'@me': {
//.
patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPICurrentGuildMemberJSONBody>,
): Promise<RESTGetAPIGuildMemberResult>;
@ -203,133 +183,102 @@ export interface GuildRoutes {
(
id: string,
): {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildMemberResult>;
//.
put(
args?: RestArguments<ProxyRequestMethod.Put, RESTPutAPIGuildMemberJSONBody>,
): Promise<RESTPutAPIGuildMemberResult>;
//.
//.
patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildMemberJSONBody>,
): Promise<RESTPatchAPIGuildMemberResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIGuildMemberResult>;
roles(id: string): {
//.
put(args?: RestArguments<ProxyRequestMethod.Put>): Promise<RESTPutAPIGuildMemberRoleResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIGuildMemberRoleResult>;
};
};
};
threads: {
active: {
//.
get(
args?: RestArguments<ProxyRequestMethod.Get>,
): Promise<Identify<RESTGetAPIGuildThreadsResult & { threads: Partial<APIThreadChannel> }>>;
};
};
roles: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildRolesResult>;
//.
post(
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIGuildRoleJSONBody>,
): Promise<RESTPostAPIGuildRoleResult>;
//.
patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildRolePositionsJSONBody>,
): Promise<RESTPatchAPIGuildRolePositionsResult>;
(
id: string,
): {
//.
patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildRoleJSONBody>,
): Promise<RESTPatchAPIGuildRoleResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIGuildRoleResult>;
};
};
bans: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIGuildBansQuery>): Promise<RESTGetAPIGuildBansResult>;
(
userId: string,
): {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildBanResult>;
//.
put(
args?: RestArguments<ProxyRequestMethod.Put, RESTPutAPIGuildBanJSONBody>,
): Promise<RESTPutAPIGuildBanResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIGuildBanResult>;
};
};
mfa: {
//.
post(
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIGuildsMFAJSONBody>,
): Promise<RESTPostAPIGuildsMFAResult>;
};
prune: {
//.
get(
args: RestArguments<ProxyRequestMethod.Get, RESTGetAPIGuildPruneCountQuery>,
): Promise<RESTGetAPIGuildPruneCountResult>;
//.
post(
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIGuildPruneJSONBody>,
): Promise<RESTPostAPIGuildPruneResult>;
};
regions: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildVoiceRegionsResult>;
};
invites: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildInvitesResult>;
};
widget: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildWidgetSettingsResult>;
//.
patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildWidgetSettingsJSONBody>,
): Promise<RESTPatchAPIGuildWidgetSettingsResult>;
};
'widget.json': {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildWidgetJSONResult>;
};
'widget.png': {
//.
get(
args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIGuildWidgetImageQuery>,
): Promise<RESTGetAPIGuildWidgetImageResult>;
};
integrations: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildIntegrationsResult>;
(
id: string,
): {
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIGuildIntegrationResult>;
};
};
'vanity-url': {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildVanityUrlResult>;
};
'welcome-screen': {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildWelcomeScreenResult>;
//.
patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildWelcomeScreenJSONBody>,
): Promise<RESTPatchAPIGuildWelcomeScreenResult>;
@ -338,28 +287,22 @@ export interface GuildRoutes {
// get(args:RestArguments<ProxyRequestMethod.Get,boarding>);
// }
emojis: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildEmojisResult>;
//.
post(
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIGuildEmojiJSONBody>,
): Promise<RESTPostAPIGuildEmojiResult>;
(
id: string,
): {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildEmojiResult>;
//.
patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildEmojiJSONBody>,
): Promise<RESTPatchAPIGuildEmojiResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIGuildEmojiResult>;
};
};
'voice-states': {
'@me': {
//.
patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody>,
): Promise<RESTPatchAPIGuildVoiceStateCurrentMemberResult>;
@ -367,16 +310,13 @@ export interface GuildRoutes {
(
id: string,
): {
//.
patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildVoiceStateUserJSONBody>,
): Promise<RESTPatchAPIGuildVoiceStateUserResult>;
};
};
stickers: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildStickersResult>;
//.
post(
args: RestArguments<
ProxyRequestMethod.Post,
@ -388,40 +328,31 @@ export interface GuildRoutes {
(
id: string,
): {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildStickerResult>;
//.
patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildStickerJSONBody>,
): Promise<RESTPatchAPIGuildStickerResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIGuildStickerResult>;
};
};
'scheduled-events': {
//.
get(
args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIGuildScheduledEventsQuery>,
): Promise<RESTGetAPIGuildScheduledEventsResult>;
//.
post(
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIGuildScheduledEventJSONBody>,
): Promise<RESTPostAPIGuildScheduledEventResult>;
(
id: string,
): {
//.
get(
args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIGuildScheduledEventQuery>,
): Promise<RESTGetAPIGuildScheduledEventResult>;
//.
patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildScheduledEventJSONBody>,
): Promise<RESTPatchAPIGuildScheduledEventResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIGuildScheduledEventResult>;
users: {
//.
get(
args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPIGuildScheduledEventUsersQuery>,
): Promise<RESTGetAPIGuildScheduledEventUsersResult>;
@ -429,22 +360,17 @@ export interface GuildRoutes {
};
};
templates: {
//.
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIGuildTemplatesResult>;
//.
post(
args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIGuildTemplatesJSONBody>,
): Promise<RESTPostAPIGuildTemplatesResult>;
(
code: string,
): {
//.
put(args?: RestArguments<ProxyRequestMethod.Put>): Promise<RESTPutAPIGuildTemplateSyncResult>;
//.
patch(
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildTemplateJSONBody>,
): Promise<RESTPatchAPIGuildTemplateResult>;
//.
delete(args?: RestArguments<ProxyRequestMethod.Delete>): Promise<RESTDeleteAPIGuildTemplateResult>;
};
};

View File

@ -14,16 +14,17 @@ export class Messages extends GuildRelatedResource {
override parse(data: any, _key: string, _channel_id: string) {
const { author, member, ...rest } = data;
rest.user_id = author.id;
if (author?.id) rest.user_id = author.id;
return rest;
}
override get(id: string): ReturnCache<Message | undefined> {
return fakePromise(super.get(id) as APIMessageResource).then(rawMessage => {
const user = this.cache.users
? (this.cache.adapter.get(this.cache.users.hashId(rawMessage.user_id)) as APIUser | undefined)
: undefined;
const user =
this.cache.users && rawMessage.user_id
? (this.cache.adapter.get(this.cache.users.hashId(rawMessage.user_id)) as APIUser | undefined)
: undefined;
return user ? new Message(this.client, { ...rawMessage, author: user }) : undefined;
});
}
@ -33,9 +34,10 @@ export class Messages extends GuildRelatedResource {
messages =>
messages
.map(rawMessage => {
const user = this.cache.users
? (this.cache.adapter.get(this.cache.users.hashId(rawMessage.user_id)) as APIUser | undefined)
: undefined;
const user =
this.cache.users && rawMessage.user_id
? (this.cache.adapter.get(this.cache.users.hashId(rawMessage.user_id)) as APIUser | undefined)
: undefined;
return user ? new Message(this.client, { ...rawMessage, author: user }) : undefined;
})
.filter(Boolean) as Message[],
@ -44,8 +46,10 @@ export class Messages extends GuildRelatedResource {
override values(guild: string): ReturnCache<Message[]> {
return fakePromise(super.values(guild) as APIMessageResource[]).then(messages => {
const hashes: string[] = this.cache.users ? messages.map(x => this.cache.users!.hashId(x.user_id)) : [];
return fakePromise(this.cache.adapter.get(hashes) as APIUser[]).then(users => {
const hashes: (string | undefined)[] = this.cache.users
? messages.map(x => (x.user_id ? this.cache.users!.hashId(x.user_id) : undefined))
: [];
return fakePromise(this.cache.adapter.get(hashes.filter(Boolean) as string[]) as APIUser[]).then(users => {
return messages
.map(message => {
const user = users.find(user => user.id === message.user_id);
@ -57,4 +61,4 @@ export class Messages extends GuildRelatedResource {
}
}
export type APIMessageResource = Omit<APIMessage, 'author'> & { user_id: string };
export type APIMessageResource = Omit<APIMessage, 'author'> & { user_id?: string };

View File

@ -38,7 +38,7 @@ import {
} from 'discord-api-types/v10';
import { mix } from 'ts-mixer';
import type { RawFile } from '../api';
import { ActionRow, Embed, Modal, resolveAttachment, resolveFiles } from '../builders';
import { ActionRow, Embed, Modal, PollBuilder, resolveAttachment, resolveFiles } from '../builders';
import { OptionResolver, type ContextOptionsResolved, type UsingClient } from '../commands';
import type { ObjectToLower, OmitInsert, ToClass, When } from '../common';
import type {
@ -132,7 +132,7 @@ export class BaseInteraction<
components: body.data?.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)) ?? undefined,
embeds: body.data?.embeds?.map(x => (x instanceof Embed ? x.toJSON() : x)) ?? undefined,
attachments: body.data?.attachments?.map((x, i) => ({ id: i, ...resolveAttachment(x) })) ?? undefined,
poll: poll ? ('toJSON' in poll ? poll.toJSON() : poll) : undefined,
poll: poll ? (poll instanceof PollBuilder ? poll.toJSON() : poll) : undefined,
},
};
}
@ -170,8 +170,7 @@ export class BaseInteraction<
...body,
components: body.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)) ?? undefined,
embeds: body?.embeds?.map(x => (x instanceof Embed ? x.toJSON() : x)) ?? undefined,
poll: poll ? ('toJSON' in poll ? poll.toJSON() : poll) : undefined,
// attachments: body.attachments?.map((x, i) => ({ id: i, ...resolveAttachment(x) })) ?? undefined,
poll: poll ? (poll instanceof PollBuilder ? poll.toJSON() : poll) : undefined,
} as T;
}

View File

@ -25,7 +25,7 @@ import {
type ThreadAutoArchiveDuration,
} from 'discord-api-types/v10';
import { mix } from 'ts-mixer';
import { Embed, resolveAttachment } from '../builders';
import { ActionRow, Embed, PollBuilder, resolveAttachment } from '../builders';
import type { UsingClient } from '../commands';
import type {
EmojiResolvable,
@ -254,10 +254,10 @@ export class MessagesMethods extends DiscordBase {
const poll = (body as MessageCreateBodyRequest).poll;
return {
...body,
components: body.components?.map(x => ('toJSON' in x ? x.toJSON() : x)) ?? undefined,
components: body.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)) ?? undefined,
embeds: body.embeds?.map(x => (x instanceof Embed ? x.toJSON() : x)) ?? undefined,
attachments: body.attachments?.map((x, i) => ({ id: i, ...resolveAttachment(x) })) ?? undefined,
poll: poll ? ('toJSON' in poll ? poll.toJSON() : poll) : undefined,
poll: poll ? (poll instanceof PollBuilder ? poll.toJSON() : poll) : undefined,
} as T;
}
}