From 55064c16a72c01f22c66f6ade09dfd47392750c6 Mon Sep 17 00:00:00 2001 From: YordiGamex <44493931+YordiGamex@users.noreply.github.com> Date: Mon, 14 Jul 2025 12:05:28 -0500 Subject: [PATCH 1/2] Create getComponents.js This is a function I made, it is used to read components, it helps a lot since now some bots are using v2 components, so it would be good to get ahead of that kind of things Use: $getComponents[$channelID?;$messageID] --- src/functions/embeds/getComponents.js | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/functions/embeds/getComponents.js diff --git a/src/functions/embeds/getComponents.js b/src/functions/embeds/getComponents.js new file mode 100644 index 000000000..6156fa915 --- /dev/null +++ b/src/functions/embeds/getComponents.js @@ -0,0 +1,59 @@ +/** + * @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] = data.inside.splits; + + if (!messageID) { + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "You must provide the message ID." + ); + } + + const channel = d.client.channels.cache.get(channelID); + if (!channel) { + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + `Channel with ID "${channelID}" was not found.` + ); + } + + let msg; + try { + msg = await channel.messages.fetch(messageID); + } catch { + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + `Failed to fetch message with ID "${messageID}".` + ); + } + + if (!msg.components?.length) { + return d.aoiError.fnError( + d, + "custom", + { inside: data.inside }, + "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) + }; +}; From a4671334be9186b4163bd1b444a961e0923b5f81 Mon Sep 17 00:00:00 2001 From: YordiGamex <44493931+YordiGamex@users.noreply.github.com> Date: Mon, 14 Jul 2025 14:00:54 -0500 Subject: [PATCH 2/2] Update getComponents.js I already made the changes you mentioned above. --- src/functions/embeds/getComponents.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/functions/embeds/getComponents.js b/src/functions/embeds/getComponents.js index 6156fa915..05d8fee8a 100644 --- a/src/functions/embeds/getComponents.js +++ b/src/functions/embeds/getComponents.js @@ -5,24 +5,22 @@ module.exports = async (d) => { const data = d.util.aoiFunc(d); if (data.err) return d.error(data.err); - const [channelID = d.channel?.id, messageID] = data.inside.splits; + const [channelID = d.channel?.id, messageID = d.message?.id] = data.inside.splits; if (!messageID) { return d.aoiError.fnError( d, - "custom", + "message", { inside: data.inside }, - "You must provide the message ID." ); } - const channel = d.client.channels.cache.get(channelID); - if (!channel) { + const channel = d.util.getChannel(channelID); + if (!channel) { return d.aoiError.fnError( d, - "custom", + "channel", { inside: data.inside }, - `Channel with ID "${channelID}" was not found.` ); } @@ -32,17 +30,15 @@ module.exports = async (d) => { } catch { return d.aoiError.fnError( d, - "custom", + "message", { inside: data.inside }, - `Failed to fetch message with ID "${messageID}".` ); - } if (!msg.components?.length) { return d.aoiError.fnError( d, "custom", - { inside: data.inside }, + {}, "The message does not contain any components." ); }