(client, guildId, userId, options = {})
| 292 | } |
| 293 | |
| 294 | export async function removeVerification(client, guildId, userId, options = {}) { |
| 295 | const { moderatorId = null, reason = 'admin_removal' } = options; |
| 296 | |
| 297 | try { |
| 298 | const guild = client.guilds.cache.get(guildId); |
| 299 | if (!guild) { |
| 300 | throw createError( |
| 301 | `Guild ${guildId} not found`, |
| 302 | ErrorTypes.CONFIGURATION, |
| 303 | "Guild not found.", |
| 304 | { guildId } |
| 305 | ); |
| 306 | } |
| 307 | |
| 308 | let member; |
| 309 | try { |
| 310 | member = await guild.members.fetch(userId); |
| 311 | } catch (error) { |
| 312 | throw createError( |
| 313 | `Member ${userId} not found`, |
| 314 | ErrorTypes.USER_INPUT, |
| 315 | "User is not in this server.", |
| 316 | { userId } |
| 317 | ); |
| 318 | } |
| 319 | |
| 320 | const guildConfig = await getGuildConfig(client, guildId); |
| 321 | |
| 322 | if (!guildConfig.verification?.enabled) { |
| 323 | throw createError( |
| 324 | "Verification system disabled", |
| 325 | ErrorTypes.CONFIGURATION, |
| 326 | "The verification system is not enabled.", |
| 327 | { guildId } |
| 328 | ); |
| 329 | } |
| 330 | |
| 331 | const verifiedRole = guild.roles.cache.get(guildConfig.verification.roleId); |
| 332 | if (!verifiedRole) { |
| 333 | throw createError( |
| 334 | "Verified role not found", |
| 335 | ErrorTypes.CONFIGURATION, |
| 336 | "The verified role no longer exists.", |
| 337 | { roleId: guildConfig.verification.roleId } |
| 338 | ); |
| 339 | } |
| 340 | |
| 341 | const canAssignRole = await validateBotCanAssignRole(guild, verifiedRole.id); |
| 342 | if (!canAssignRole) { |
| 343 | throw createError( |
| 344 | 'Bot cannot manage verified role', |
| 345 | ErrorTypes.PERMISSION, |
| 346 | "I can't remove the verified role right now. Please check my **Manage Roles** permission and role hierarchy.", |
| 347 | { guildId, roleId: verifiedRole.id } |
| 348 | ); |
| 349 | } |
| 350 | |
| 351 | if (!member.roles.cache.has(verifiedRole.id)) { |
no test coverage detected