MCPcopy
hub / github.com/codebymitch/TitanBot / handleLogChannel

Function handleLogChannel

src/commands/Community/modules/app_dashboard.js:676–737  ·  view source on GitHub ↗
(selectInteraction, rootInteraction, settings, roles, guildId, client, selectedRoleId)

Source from the content-addressed store, hash-verified

674}
675
676async function handleLogChannel(selectInteraction, rootInteraction, settings, roles, guildId, client, selectedRoleId) {
677 let currentChannel = settings.logChannelId;
678 if (selectedRoleId) {
679 const roleSettings = await getApplicationRoleSettings(client, guildId, selectedRoleId);
680 currentChannel = roleSettings.logChannelId || settings.logChannelId;
681 }
682
683 const modal = new ModalBuilder()
684 .setCustomId(`app_cfg_log_channel_modal_${guildId}_${selectedRoleId || 'global'}`)
685 .setTitle('Configure Log Channel');
686
687 const channelSelect = new ChannelSelectMenuBuilder()
688 .setCustomId('log_channel')
689 .setPlaceholder('Select a text channel...')
690 .setMinValues(1)
691 .setMaxValues(1)
692 .addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement)
693 .setRequired(true);
694
695 const channelLabel = new LabelBuilder()
696 .setLabel('Log Channel')
697 .setDescription('Channel where new applications will be logged')
698 .setChannelSelectMenuComponent(channelSelect);
699
700 modal.addLabelComponents(channelLabel);
701
702 await selectInteraction.showModal(modal);
703
704 try {
705 const modalSubmission = await selectInteraction.awaitModalSubmit({
706 time: 5 * 60 * 1000,
707 filter: i => i.user.id === selectInteraction.user.id && i.customId === `app_cfg_log_channel_modal_${guildId}_${selectedRoleId || 'global'}`,
708 });
709
710 const channelId = modalSubmission.fields.getField('log_channel').values[0];
711 const channel = selectInteraction.guild.channels.cache.get(channelId);
712
713 if (selectedRoleId) {
714 const roleSettings = await getApplicationRoleSettings(client, guildId, selectedRoleId);
715 roleSettings.logChannelId = channelId;
716 await saveApplicationRoleSettings(client, guildId, selectedRoleId, roleSettings);
717 } else {
718 await setLogChannel(client, guildId, 'applications', channelId);
719 settings.logChannelId = channelId;
720 await saveApplicationSettings(client, guildId, settings);
721 }
722
723 await modalSubmission.reply({
724 embeds: [successEmbed('Log Channel Updated', `Application logs will now be sent to ${channel ?? `<#${channelId}>`}.\nYou can also manage this from \`/logging dashboard\`.`)],
725 flags: MessageFlags.Ephemeral,
726 });
727
728 await refreshDashboard(rootInteraction, settings, roles, guildId, client);
729 } catch (error) {
730 if (error.code === 'INTERACTION_TIMEOUT') return;
731 logger.error('Error in log channel modal:', error);
732 await replyUserError(selectInteraction, {
733 type: ErrorTypes.UNKNOWN,

Callers 1

setupCollectorsFunction · 0.85

Calls 8

setLogChannelFunction · 0.90
saveApplicationSettingsFunction · 0.90
successEmbedFunction · 0.90
replyUserErrorFunction · 0.90
refreshDashboardFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected