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

Function handleSetup

src/commands/Verification/modules/autoVerify.js:81–190  ·  view source on GitHub ↗
(interaction, guild, client)

Source from the content-addressed store, hash-verified

79};
80
81async function handleSetup(interaction, guild, client) {
82 const criteria = interaction.options.getString("criteria");
83 const accountAgeDays = interaction.options.getInteger("account_age_days") || defaultAccountAgeDays;
84 const targetRole = interaction.options.getRole("role");
85
86 await InteractionHelper.safeDefer(interaction);
87
88 try {
89 const guildConfig = await getGuildConfig(client, guild.id);
90 const welcomeConfig = await getWelcomeConfig(client, guild.id);
91 const verificationEnabled = Boolean(guildConfig.verification?.enabled);
92 const hasAutoRoleConfigured = Boolean(guildConfig.autoRole) || (Array.isArray(welcomeConfig.roleIds) && welcomeConfig.roleIds.length > 0);
93
94 if (verificationEnabled || hasAutoRoleConfigured) {
95 throw createError(
96 'Auto-verify enable blocked by conflicting onboarding system',
97 ErrorTypes.CONFIGURATION,
98 'You cannot enable **AutoVerify** while the verification system or AutoRole is configured. Disable those first.',
99 {
100 guildId: guild.id,
101 verificationEnabled,
102 hasAutoRoleConfigured,
103 expected: true,
104 suppressErrorLog: true
105 }
106 );
107 }
108
109 const botMember = guild.members.me;
110 if (!botMember) {
111 throw createError(
112 'Bot member not found in guild cache',
113 ErrorTypes.CONFIGURATION,
114 'I could not verify my permissions in this server. Please try again in a moment.',
115 { guildId: guild.id }
116 );
117 }
118
119 if (!botMember.permissions.has(PermissionFlagsBits.ManageRoles)) {
120 throw createError(
121 'Missing ManageRoles permission',
122 ErrorTypes.PERMISSION,
123 "I need the 'Manage Roles' permission to assign auto-verify roles.",
124 { guildId: guild.id }
125 );
126 }
127
128 if (targetRole.id === guild.id || targetRole.managed) {
129 throw createError(
130 'Invalid auto-verify role selected',
131 ErrorTypes.VALIDATION,
132 'Please choose a normal assignable role (not @everyone or an integration-managed role).',
133 { guildId: guild.id, roleId: targetRole.id, managed: targetRole.managed }
134 );
135 }
136
137 if (targetRole.position >= botMember.roles.highest.position) {
138 throw createError(

Callers 1

executeFunction · 0.70

Calls 8

getGuildConfigFunction · 0.90
getWelcomeConfigFunction · 0.90
createErrorFunction · 0.90
setGuildConfigFunction · 0.90
successEmbedFunction · 0.90
safeDeferMethod · 0.80
safeEditReplyMethod · 0.80

Tested by

no test coverage detected