fix: embeds (#215)

This commit is contained in:
Marcos Susaña 2024-06-26 18:40:19 -04:00 committed by GitHub
parent ad5edad727
commit ddc6dab0db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 38 deletions

View File

@ -133,26 +133,10 @@ export class BaseInteraction<
return body; return body;
case InteractionResponseType.ChannelMessageWithSource: case InteractionResponseType.ChannelMessageWithSource:
case InteractionResponseType.UpdateMessage: { case InteractionResponseType.UpdateMessage: {
const poll = (body as InteractionCreateBodyRequest).poll;
return { return {
type: body.type, type: body.type,
//@ts-ignore //@ts-ignore
data: { data: BaseInteraction.transformBodyRequest(body.data ?? {}, files, self),
//@ts-ignore
allowed_mentions: self.options?.allowedMentions,
...(body.data ?? {}),
//@ts-ignore
components: body.data?.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)),
embeds: body.data?.embeds?.map(x => (x instanceof Embed ? x.toJSON() : x)),
attachments:
body.data && 'attachments' in body.data
? body.data.attachments?.map((x, i) => ({ id: i, ...resolveAttachment(x) }))
: (files?.map((x, id) => ({
id,
filename: x.name,
})) as RESTAPIAttachment[]),
poll: poll ? (poll instanceof PollBuilder ? poll.toJSON() : poll) : undefined,
},
}; };
} }
case InteractionResponseType.Modal: case InteractionResponseType.Modal:
@ -188,20 +172,28 @@ export class BaseInteraction<
) { ) {
const poll = (body as MessageWebhookCreateBodyRequest).poll; const poll = (body as MessageWebhookCreateBodyRequest).poll;
return { const allow = {
allowed_mentions: self.options?.allowedMentions, allowed_mentions: self.options?.allowedMentions,
attachments:
'attachments' in body
? body.attachments?.map((x, i) => ({ id: i, ...resolveAttachment(x) }))
: (files?.map((x, id) => ({
id,
filename: x.name,
})) as RESTAPIAttachment[]),
...body, ...body,
components: body.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)), components: body.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)),
embeds: body?.embeds?.map(x => (x instanceof Embed ? x.toJSON() : x)), embeds: body?.embeds?.map(x => (x instanceof Embed ? x.toJSON() : x)),
poll: poll ? (poll instanceof PollBuilder ? poll.toJSON() : poll) : undefined, poll: poll ? (poll instanceof PollBuilder ? poll.toJSON() : poll) : undefined,
} as T; };
if ('attachment' in body) {
allow.attachments =
body.attachments?.map((x, i) => ({
id: i,
...resolveAttachment(x),
})) ?? undefined;
} else if (files?.length) {
allow.attachments = files?.map((x, id) => ({
id,
filename: x.name,
})) as RESTAPIAttachment[];
}
return allow as unknown as T;
} }
private async matchReplied(body: ReplyInteractionBody) { private async matchReplied(body: ReplyInteractionBody) {

View File

@ -280,23 +280,27 @@ export class MessagesMethods extends DiscordBase {
self: UsingClient, self: UsingClient,
) { ) {
const poll = (body as MessageCreateBodyRequest).poll; const poll = (body as MessageCreateBodyRequest).poll;
return { const allow = {
allowed_mentions: self.options?.allowedMentions, allowed_mentions: self.options?.allowedMentions,
...body, ...body,
components: body.components?.map(x => (x instanceof ActionRow ? 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, embeds: body.embeds?.map(x => (x instanceof Embed ? x.toJSON() : x)) ?? undefined,
attachments:
'attachments' in body
? body.attachments?.map((x, i) => ({
id: i,
...resolveAttachment(x),
})) ?? undefined
: (files?.map((x, id) => ({
id,
filename: x.name,
})) as RESTAPIAttachment[]),
poll: poll ? (poll instanceof PollBuilder ? poll.toJSON() : poll) : undefined, poll: poll ? (poll instanceof PollBuilder ? poll.toJSON() : poll) : undefined,
} as T; };
if ('attachment' in body) {
allow.attachments =
body.attachments?.map((x, i) => ({
id: i,
...resolveAttachment(x),
})) ?? undefined;
} else if (files?.length) {
allow.attachments = files?.map((x, id) => ({
id,
filename: x.name,
})) as RESTAPIAttachment[];
}
return allow as unknown as T;
} }
} }