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

Function handleUserLimitModal

src/commands/JoinToCreate/jointocreate.js:453–519  ·  view source on GitHub ↗
(interaction, triggerChannel, currentConfig, client)

Source from the content-addressed store, hash-verified

451}
452
453async function handleUserLimitModal(interaction, triggerChannel, currentConfig, client) {
454 try {
455 const currentLimit = currentConfig.channelConfig.userLimit ?? currentConfig.userLimit ?? 0;
456
457 const modal = new ModalBuilder()
458 .setCustomId(`jtc_limit_modal_${triggerChannel.id}`)
459 .setTitle('Configure User Limit')
460 .addComponents(
461 new ActionRowBuilder().addComponents(
462 new TextInputBuilder()
463 .setCustomId('user_limit')
464 .setLabel('Enter user limit (0-99, 0 = unlimited)')
465 .setPlaceholder('Enter a number between 0 and 99')
466 .setStyle(TextInputStyle.Short)
467 .setRequired(true)
468 .setMinLength(1)
469 .setMaxLength(2)
470 .setValue(currentLimit.toString())
471 )
472 );
473
474 await interaction.showModal(modal);
475
476 const modalSubmission = await interaction.awaitModalSubmit({
477 filter: (i) => i.customId === `jtc_limit_modal_${triggerChannel.id}` && i.user.id === interaction.user.id,
478 time: 60000
479 });
480
481 if (!hasManageGuildPermission(modalSubmission.member)) {
482 await modalSubmission.reply({
483 content: '❌ You need **Manage Server** permission to modify these settings.',
484 flags: MessageFlags.Ephemeral
485 });
486 return;
487 }
488
489 const userInput = modalSubmission.fields.getTextInputValue('user_limit').trim();
490
491 await updateChannelConfig(client, interaction.guild.id, triggerChannel.id, {
492 userLimit: parseInt(userInput)
493 });
494
495 await logConfigurationChange(client, interaction.guild.id, interaction.user.id, 'Updated user limit', {
496 channelId: triggerChannel.id,
497 userLimit: parseInt(userInput)
498 });
499
500 await modalSubmission.reply({
501 embeds: [successEmbed('Updated', `User limit changed to ${parseInt(userInput) === 0 ? 'Unlimited' : parseInt(userInput) + ' users'}`)],
502 flags: MessageFlags.Ephemeral
503 });
504
505 } catch (error) {
506 if (error.code === 'INTERACTION_COLLECTOR_ERROR') {
507 return;
508 }
509 if (error instanceof TitanBotError) {
510 throw error;

Callers 1

handleConfigSubcommandFunction · 0.85

Calls 4

hasManageGuildPermissionFunction · 0.90
updateChannelConfigFunction · 0.90
logConfigurationChangeFunction · 0.90
successEmbedFunction · 0.90

Tested by

no test coverage detected