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

Function rebuildLivePanelMessage

src/commands/Reaction_roles/reactroles.js:375–420  ·  view source on GitHub ↗
(guild, panelData)

Source from the content-addressed store, hash-verified

373}
374
375async function rebuildLivePanelMessage(guild, panelData) {
376 try {
377 const channel = guild.channels.cache.get(panelData.channelId);
378 if (!channel) return;
379 const msg = await channel.messages.fetch(panelData.messageId).catch(() => null);
380 if (!msg || !msg.embeds[0]) return;
381
382 const roleObjects = panelData.roles
383 .map(id => guild.roles.cache.get(id))
384 .filter(Boolean);
385
386 if (roleObjects.length === 0) return;
387
388 const currentEmbed = msg.embeds[0];
389 const updatedEmbed = EmbedBuilder.from(currentEmbed);
390 const fields = currentEmbed.fields.map(f => ({ name: f.name, value: f.value, inline: f.inline }));
391 const roleFieldIdx = fields.findIndex(f => f.name === 'Available Roles');
392 const newRoleValue = roleObjects.map(r => `• ${r}`).join('\n');
393 if (roleFieldIdx !== -1) {
394 fields[roleFieldIdx] = { name: 'Available Roles', value: newRoleValue, inline: false };
395 } else {
396 fields.push({ name: 'Available Roles', value: newRoleValue, inline: false });
397 }
398 updatedEmbed.setFields(fields);
399
400 const selectRow = new ActionRowBuilder().addComponents(
401 new StringSelectMenuBuilder()
402 .setCustomId('reaction_roles')
403 .setPlaceholder('Select your roles')
404 .setMinValues(0)
405 .setMaxValues(roleObjects.length)
406 .addOptions(
407 roleObjects.map(r => ({
408 label: r.name.substring(0, 100),
409 description: `Add/remove the ${r.name} role`.substring(0, 100),
410 value: r.id,
411 emoji: '🎭',
412 })),
413 ),
414 );
415
416 await msg.edit({ embeds: [updatedEmbed], components: [selectRow] });
417 } catch (error) {
418 logger.warn('Could not rebuild live reaction role panel:', error.message);
419 }
420}
421
422async function showPanelDashboard(interaction, panelData, discordMsg, guildId, guild) {
423 const channel = guild.channels.cache.get(panelData.channelId);

Callers 2

handleAddRoleFunction · 0.85
handleRemoveRoleFunction · 0.85

Calls 2

editMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected