(guild, verificationConfig)
| 403 | } |
| 404 | |
| 405 | export async function validateVerificationSetup(guild, verificationConfig) { |
| 406 | const botMember = guild.members.me; |
| 407 | if (!botMember) { |
| 408 | throw createError( |
| 409 | 'Bot member not available in guild cache', |
| 410 | ErrorTypes.CONFIGURATION, |
| 411 | "I couldn't verify my server permissions. Please try again.", |
| 412 | { guildId: guild.id } |
| 413 | ); |
| 414 | } |
| 415 | |
| 416 | const verifiedRole = guild.roles.cache.get(verificationConfig.roleId); |
| 417 | if (!verifiedRole) { |
| 418 | throw createError( |
| 419 | "Verified role not found", |
| 420 | ErrorTypes.CONFIGURATION, |
| 421 | "The verified role was deleted. Please run `/verification setup` again.", |
| 422 | { roleId: verificationConfig.roleId, guildId: guild.id } |
| 423 | ); |
| 424 | } |
| 425 | |
| 426 | if (verificationConfig.channelId) { |
| 427 | const channel = guild.channels.cache.get(verificationConfig.channelId); |
| 428 | if (!channel) { |
| 429 | throw createError( |
| 430 | "Verification channel not found", |
| 431 | ErrorTypes.CONFIGURATION, |
| 432 | "The verification channel was deleted.", |
| 433 | { channelId: verificationConfig.channelId, guildId: guild.id } |
| 434 | ); |
| 435 | } |
| 436 | |
| 437 | const botPerms = channel.permissionsFor(botMember); |
| 438 | const requiredPerms = ['ViewChannel', 'SendMessages', 'EmbedLinks']; |
| 439 | const missingPerms = requiredPerms.filter(perm => !botPerms.has(perm)); |
| 440 | |
| 441 | if (missingPerms.length > 0) { |
| 442 | throw createError( |
| 443 | "Bot missing permissions in verification channel", |
| 444 | ErrorTypes.PERMISSION, |
| 445 | `I'm missing permissions in the verification channel: ${missingPerms.join(', ')}`, |
| 446 | { missingPerms, channelId: channel.id } |
| 447 | ); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | return true; |
| 452 | } |
| 453 | |
| 454 | export async function validateBotCanAssignRole(guild, roleId) { |
| 455 | const role = guild.roles.cache.get(roleId); |
no test coverage detected