(selectInteraction, rootInteraction, settings, roles, guildId, client)
| 903 | } |
| 904 | |
| 905 | async function handleRoleAdd(selectInteraction, rootInteraction, settings, roles, guildId, client) { |
| 906 | const modal = new ModalBuilder() |
| 907 | .setCustomId(`app_cfg_role_add_modal_${guildId}`) |
| 908 | .setTitle('Add Application Role'); |
| 909 | |
| 910 | const roleSelect = new RoleSelectMenuBuilder() |
| 911 | .setCustomId('application_role') |
| 912 | .setPlaceholder('Select the role members can apply for...') |
| 913 | .setMinValues(1) |
| 914 | .setMaxValues(1) |
| 915 | .setRequired(true); |
| 916 | |
| 917 | const roleLabel = new LabelBuilder() |
| 918 | .setLabel('Application Role') |
| 919 | .setDescription('Select the Discord role members will be applying for') |
| 920 | .setRoleSelectMenuComponent(roleSelect); |
| 921 | |
| 922 | const nameInput = new TextInputBuilder() |
| 923 | .setCustomId('role_name') |
| 924 | .setLabel('Display name (leave blank to use role name)') |
| 925 | .setStyle(TextInputStyle.Short) |
| 926 | .setMaxLength(50) |
| 927 | .setRequired(false); |
| 928 | |
| 929 | modal.addLabelComponents(roleLabel); |
| 930 | modal.addComponents(new ActionRowBuilder().addComponents(nameInput)); |
| 931 | |
| 932 | await selectInteraction.showModal(modal); |
| 933 | |
| 934 | try { |
| 935 | const modalSubmission = await selectInteraction.awaitModalSubmit({ |
| 936 | time: 5 * 60 * 1000, |
| 937 | filter: i => i.user.id === selectInteraction.user.id && i.customId === `app_cfg_role_add_modal_${guildId}`, |
| 938 | }); |
| 939 | |
| 940 | const roleId = modalSubmission.fields.getField('application_role').values[0]; |
| 941 | const role = selectInteraction.guild.roles.cache.get(roleId); |
| 942 | const customName = modalSubmission.fields.getTextInputValue('role_name').trim() || role?.name || roleId; |
| 943 | |
| 944 | if (roles.some(r => r.roleId === roleId)) { |
| 945 | await replyUserError(modalSubmission, { type: ErrorTypes.UNKNOWN, message: '${role ?? roleId} is already an application role.' }); |
| 946 | return; |
| 947 | } |
| 948 | |
| 949 | roles.push({ roleId, name: customName }); |
| 950 | await saveApplicationRoles(client, guildId, roles); |
| 951 | |
| 952 | await modalSubmission.reply({ |
| 953 | embeds: [successEmbed('Role Added', `${role ?? roleId} added as **${customName}**.`)], |
| 954 | flags: MessageFlags.Ephemeral, |
| 955 | }); |
| 956 | |
| 957 | await refreshDashboard(rootInteraction, settings, roles, guildId, client); |
| 958 | } catch (error) { |
| 959 | if (error.code === 'INTERACTION_TIMEOUT') return; |
| 960 | logger.error('Error in role add modal:', error); |
| 961 | await replyUserError(selectInteraction, { |
| 962 | type: ErrorTypes.UNKNOWN, |
no test coverage detected