Skip to content

Commit

Permalink
Merge pull request #492 from aho-emi/aho-emi-patch-1
Browse files Browse the repository at this point in the history
feat($editButton)
  • Loading branch information
Leref authored Oct 30, 2023
2 parents 3ce2971 + 7487860 commit 1512650
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/functions/interaction/editButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { ButtonBuilder, ActionRowBuilder } = require('discord.js');

module.exports = async (d) => {
const data = d.util.aoiFunc(d);
const inside = d.unpack();
if (data.err) return d.error(data.err);

let [index, customId, custom, label, style, disabled, emoji, messageID, channelID = d.channel.id] = data.inside.splits;

const channel = await d.util.getChannel(d, channelID);
if (!channel) return d.aoiError.fnError(d, "channel", { inside: data.inside });
const message = await d.util.getMessage(channel, messageID);
if (!message) return d.aoiError.fnError(d, "message", { inside: data.inside });
if (!customId) return d.aoiError.fnError(d, "custom", { inside }, "Empty customId was provided");
if (isNaN(index) || Number(index) < 1) d.aoiError.fnError(d, "custom", {inside}, "Invalid Index Provided In");
index = Number(index) - 1;
if (style) {
style = d.util.constants.ButtonStyleOptions[style] || Number(style);
if (style > 5 || style < 1) d.aoiError.fnError(d, "custom", { inside }, "Invalid Style Provided In");
}
const components = message.components;
if (!components[index]) components[index] = { type: 1, components: [] };
const rows = [];
components[index].components.forEach(button => {
if (button.customId === customId) {
const newButton = new ButtonBuilder()
.setLabel(label || button.label)
.setStyle(style || button.style)
.setDisabled(disabled ? JSON.parse(disabled) : button.disabled);
if (emoji) newButton.setEmoji(emoji || button.emoji);
style != 5
? newButton.setCustomId(custom || button.customId)
: newButton.setURL(custom || button.url);
rows.push(newButton);
} else {
rows.push(button);
}
});
components[index] = new ActionRowBuilder().addComponents(rows);
await message.edit({ components });
return {
code: d.util.setCode(data)
};
};

0 comments on commit 1512650

Please sign in to comment.