MCPcopy Create free account
hub / github.com/codebymitch/TitanBot / handlePostEmbed

Function handlePostEmbed

src/commands/Tools/embedbuilder.js:938–1013  ·  view source on GitHub ↗
(selectInteraction, rootInteraction, state, guild)

Source from the content-addressed store, hash-verified

936}
937
938async function handlePostEmbed(selectInteraction, rootInteraction, state, guild) {
939 if (
940 !state.title &&
941 !state.description &&
942 state.fields.length === 0 &&
943 !state.author?.name
944 ) {
945 await selectInteraction.deferUpdate();
946 await replyUserError(selectInteraction, {
947 type: ErrorTypes.VALIDATION,
948 message: 'Add at least a title, description, or field before posting.',
949 });
950 return;
951 }
952
953 await selectInteraction.deferUpdate();
954
955 const chanSelect = new ChannelSelectMenuBuilder()
956 .setCustomId('eb_post_channel')
957 .setPlaceholder('Select a channel...')
958 .addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement);
959
960 await selectInteraction.followUp({
961 embeds: [
962 new EmbedBuilder()
963 .setTitle('Post Embed')
964 .setDescription('Select the channel where this embed will be sent.')
965 .setColor(getColor('info')),
966 ],
967 components: [new ActionRowBuilder().addComponents(chanSelect)],
968 flags: MessageFlags.Ephemeral,
969 });
970
971 const chanCollector = rootInteraction.channel.createMessageComponentCollector({
972 componentType: ComponentType.ChannelSelect,
973 filter: i =>
974 i.user.id === selectInteraction.user.id && i.customId === 'eb_post_channel',
975 time: 60_000,
976 max: 1,
977 });
978
979 chanCollector.on('collect', async chanInter => {
980 await chanInter.deferUpdate();
981 const channel = chanInter.channels.first();
982
983 if (!channel) {
984 await replyUserError(chanInter, {
985 type: ErrorTypes.USER_INPUT,
986 message: 'Could not resolve the selected channel.',
987 });
988 return;
989 }
990
991 const perms = channel.permissionsFor(guild.members.me);
992 if (!perms?.has([PermissionFlagsBits.SendMessages, PermissionFlagsBits.EmbedLinks])) {
993 await replyUserError(chanInter, {
994 type: ErrorTypes.PERMISSION,
995 message: `I need **Send Messages** and **Embed Links** permissions in ${channel} to post there.`,

Callers 1

executeFunction · 0.85

Calls 5

replyUserErrorFunction · 0.90
getColorFunction · 0.90
successEmbedFunction · 0.90
buildPreviewEmbedFunction · 0.85
followUpMethod · 0.80

Tested by

no test coverage detected