Untitled
unknown
plain_text
a year ago
6.8 kB
16
Indexable
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ModalBuilder, TextInputBuilder, TextInputStyle, EmbedBuilder, Colors, PermissionsBitField, ChannelType } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('embedbuilder')
.setDescription('Send a custom embed [DEV ONLY]. A.K.A EmbedBuilder, SendEmbed')
.addChannelOption(option =>
option.setName('channel')
.setDescription('The channel to send the embed to.')
.setRequired(true)
.addChannelTypes(ChannelType.GuildText)),
async execute(interaction) {
const modal = new ModalBuilder()
.setCustomId('embedModal')
.setTitle('Embed Builder');
const titleInput = new TextInputBuilder()
.setCustomId('title')
.setLabel('Title')
.setStyle(TextInputStyle.Short)
.setRequired(true);
const descriptionInput = new TextInputBuilder()
.setCustomId('description')
.setLabel('Description')
.setStyle(TextInputStyle.Paragraph)
.setRequired(true);
const colorInput = new TextInputBuilder()
.setCustomId('color')
.setLabel('Color (hex code, optional)')
.setStyle(TextInputStyle.Short)
.setRequired(false);
const footerInput = new TextInputBuilder()
.setCustomId('footer')
.setLabel('Footer (optional)')
.setStyle(TextInputStyle.Short)
.setRequired(false);
const thumbnailUrlInput = new TextInputBuilder()
.setCustomId('thumbnailUrl')
.setLabel('Thumbnail URL (optional)')
.setStyle(TextInputStyle.Short)
.setRequired(false);
const imageUrlInput = new TextInputBuilder()
.setCustomId('imageUrl')
.setLabel('Image URL (optional)')
.setStyle(TextInputStyle.Short)
.setRequired(false);
const showTimestampInput = new TextInputBuilder()
.setCustomId('showTimestamp')
.setLabel('Show Timestamp? (yes/no, optional)')
.setStyle(TextInputStyle.Short)
.setRequired(false);
modal.addComponents(
new ActionRowBuilder().addComponents(titleInput),
new ActionRowBuilder().addComponents(descriptionInput),
new ActionRowBuilder().addComponents(colorInput),
new ActionRowBuilder().addComponents(footerInput),
new ActionRowBuilder().addComponents(thumbnailUrlInput),
new ActionRowBuilder().addComponents(imageUrlInput),
new ActionRowBuilder().addComponents(showTimestampInput)
);
await interaction.showModal(modal);
const filter = (i) => i.customId === 'embedModal' && i.user.id === interaction.user.id;
interaction.awaitModalSubmit({ filter, time: 60000 })
.then(async modalInteraction => {
const title = modalInteraction.fields.getTextInputValue('title');
const description = modalInteraction.fields.getTextInputValue('description');
const color = modalInteraction.fields.getTextInputValue('color') || Colors.Green;
const footer = modalInteraction.fields.getTextInputValue('footer');
const thumbnailUrl = modalInteraction.fields.getTextInputValue('thumbnailUrl');
const imageUrl = modalInteraction.fields.getTextInputValue('imageUrl');
const showTimestamp = modalInteraction.fields.getTextInputValue('showTimestamp').toLowerCase() === 'yes';
const embed = new EmbedBuilder()
.setTitle(title)
.setDescription(description)
.setColor(color);
if (footer) embed.setFooter({ text: footer });
if (thumbnailUrl) embed.setThumbnail(thumbnailUrl);
if (imageUrl) embed.setImage(imageUrl);
if (showTimestamp) embed.setTimestamp();
const sendButton = new ButtonBuilder()
.setCustomId('sendButton')
.setLabel('Send')
.setStyle(ButtonStyle.Success);
const editButton = new ButtonBuilder()
.setCustomId('editButton')
.setLabel('Edit')
.setStyle(ButtonStyle.Primary);
const cancelButton = new ButtonBuilder()
.setCustomId('cancelButton')
.setLabel('Cancel')
.setStyle(ButtonStyle.Danger);
const actionRow = new ActionRowBuilder().addComponents(sendButton, editButton, cancelButton);
await modalInteraction.reply({ embeds: [embed], components: [actionRow], ephemeral: true });
const buttonFilter = (i) => ['sendButton', 'editButton', 'cancelButton'].includes(i.customId) && i.user.id === interaction.user.id;
const collector = modalInteraction.channel.createMessageComponentCollector({ filter: buttonFilter, time: 60000 });
collector.on('collect', async buttonInteraction => {
if (buttonInteraction.customId === 'sendButton') {
const channel = interaction.options.getChannel('channel');
if (channel.type === ChannelType.GuildText && channel.permissionsFor(interaction.user).has(PermissionsBitField.Flags.SendMessages)) {
await channel.send({ embeds: [embed] });
await buttonInteraction.update({ content: 'Embed sent successfully!', embeds: [], components: [], ephemeral: true });
} else {
await buttonInteraction.update({ content: 'You do not have permission to send messages in the chosen channel.', embeds: [], components: [], ephemeral: true });
}
} else if (buttonInteraction.customId === 'editButton') {
await buttonInteraction.update({ content: 'Please edit your embed.', components: [], ephemeral: true });
await interaction.showModal(modal); // Restart the process for editing
} else if (buttonInteraction.customId === 'cancelButton') {
await buttonInteraction.update({ content: 'Embed creation canceled.', embeds: [], components: [], ephemeral: true });
}
});
})
.catch(console.error);
}
};
Editor is loading...
Leave a Comment