Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/functions/embeds/getComponents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @param {import("..").Data} d
*/
module.exports = async (d) => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

const [channelID = d.channel?.id, messageID = d.message?.id] = data.inside.splits;

if (!messageID) {
return d.aoiError.fnError(
d,
"message",
{ inside: data.inside },
);
}

const channel = d.util.getChannel(channelID);
if (!channel) {
return d.aoiError.fnError(
d,
"channel",
{ inside: data.inside },
);
}

let msg;
try {
msg = await channel.messages.fetch(messageID);
} catch {
return d.aoiError.fnError(
d,
"message",
{ inside: data.inside },
);

if (!msg.components?.length) {
return d.aoiError.fnError(
d,
"custom",
{},
"The message does not contain any components."
);
}

const rawComponents = msg.components.map(row => ({
type: 1,
components: row.components.map(comp => comp.toJSON())
}));

data.result = JSON.stringify(rawComponents, null, 2);
return {
code: d.util.setCode(data)
};
};