Skip to content

Commit

Permalink
fix: embeds (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
socram03 authored Jun 26, 2024
1 parent ad5edad commit ddc6dab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 38 deletions.
44 changes: 18 additions & 26 deletions src/structures/Interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,10 @@ export class BaseInteraction<
return body;
case InteractionResponseType.ChannelMessageWithSource:
case InteractionResponseType.UpdateMessage: {
const poll = (body as InteractionCreateBodyRequest).poll;
return {
type: body.type,
//@ts-ignore
data: {
//@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,
},
data: BaseInteraction.transformBodyRequest(body.data ?? {}, files, self),
};
}
case InteractionResponseType.Modal:
Expand Down Expand Up @@ -188,20 +172,28 @@ export class BaseInteraction<
) {
const poll = (body as MessageWebhookCreateBodyRequest).poll;

return {
const allow = {
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,
components: body.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)),
embeds: body?.embeds?.map(x => (x instanceof Embed ? x.toJSON() : x)),
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) {
Expand Down
28 changes: 16 additions & 12 deletions src/structures/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,23 +280,27 @@ export class MessagesMethods extends DiscordBase {
self: UsingClient,
) {
const poll = (body as MessageCreateBodyRequest).poll;
return {
const allow = {
allowed_mentions: self.options?.allowedMentions,
...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,
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,
} 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;
}
}

Expand Down

0 comments on commit ddc6dab

Please sign in to comment.