MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / handleSetColor

Function handleSetColor

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

Source from the content-addressed store, hash-verified

262}
263
264async function handleSetColor(selectInteraction, rootInteraction, state) {
265 await selectInteraction.deferUpdate().catch(() => {});
266
267 const colorSelect = new StringSelectMenuBuilder()
268 .setCustomId('eb_color_pick')
269 .setPlaceholder('Choose a color...')
270 .addOptions(
271 COLOR_PRESETS.map(c =>
272 new StringSelectMenuOptionBuilder()
273 .setLabel(c.label)
274 .setValue(c.value)
275 .setEmoji(c.emoji)
276 .setDescription(c.value !== '__custom__' ? c.value : 'Enter your own #RRGGBB value'),
277 ),
278 );
279
280 await selectInteraction.followUp({
281 embeds: [
282 new EmbedBuilder()
283 .setTitle('Set Color')
284 .setDescription(
285 'Select a preset color or choose **Custom Hex** to enter your own `#RRGGBB` value.',
286 )
287 .setColor(getColor('info')),
288 ],
289 components: [new ActionRowBuilder().addComponents(colorSelect)],
290 flags: MessageFlags.Ephemeral,
291 });
292
293 const colorCollector = rootInteraction.channel.createMessageComponentCollector({
294 componentType: ComponentType.StringSelect,
295 filter: i =>
296 i.user.id === selectInteraction.user.id && i.customId === 'eb_color_pick',
297 time: 60_000,
298 max: 1,
299 });
300
301 colorCollector.on('collect', async colorInter => {
302 try {
303 const picked = colorInter.values[0];
304
305 if (picked === '__custom__') {
306 const hexModal = new ModalBuilder()
307 .setCustomId('eb_custom_hex')
308 .setTitle('Custom Color')
309 .addComponents(
310 new ActionRowBuilder().addComponents(
311 new TextInputBuilder()
312 .setCustomId('hex_value')
313 .setLabel('Hex Color Code')
314 .setStyle(TextInputStyle.Short)
315 .setPlaceholder('#5865F2')
316 .setMaxLength(7)
317 .setMinLength(7)
318 .setRequired(true),
319 ),
320 );
321

Callers 1

executeFunction · 0.85

Calls 6

getColorFunction · 0.90
replyUserErrorFunction · 0.90
isValidHexFunction · 0.85
followUpMethod · 0.80
safeShowModalMethod · 0.80
refreshDashboardFunction · 0.70

Tested by

no test coverage detected