(interaction, guild, client)
| 98 | }; |
| 99 | |
| 100 | async function handleSetup(interaction, guild, client) { |
| 101 | const verificationChannel = interaction.options.getChannel("verification_channel"); |
| 102 | const verifiedRole = interaction.options.getRole("verified_role"); |
| 103 | const message = interaction.options.getString("message") || botConfig.verification.defaultMessage; |
| 104 | const buttonText = interaction.options.getString("button_text") || botConfig.verification.defaultButtonText; |
| 105 | const botMember = guild.members.me; |
| 106 | |
| 107 | if (!botMember) { |
| 108 | throw createError( |
| 109 | 'Bot member not found in guild cache', |
| 110 | ErrorTypes.CONFIGURATION, |
| 111 | 'I could not verify my permissions in this server. Please try again in a moment.', |
| 112 | { guildId: guild.id } |
| 113 | ); |
| 114 | } |
| 115 | |
| 116 | const requiredChannelPermissions = [ |
| 117 | PermissionFlagsBits.ViewChannel, |
| 118 | PermissionFlagsBits.SendMessages, |
| 119 | PermissionFlagsBits.EmbedLinks |
| 120 | ]; |
| 121 | const missingChannelPerms = requiredChannelPermissions.filter(perm => |
| 122 | !verificationChannel.permissionsFor(botMember).has(perm) |
| 123 | ); |
| 124 | |
| 125 | if (missingChannelPerms.length > 0) { |
| 126 | throw createError( |
| 127 | `Missing channel permissions: ${missingChannelPerms.join(', ')}`, |
| 128 | ErrorTypes.PERMISSION, |
| 129 | 'I need **View Channel**, **Send Messages**, and **Embed Links** in the verification channel.', |
| 130 | { missingPermissions: missingChannelPerms, channel: verificationChannel.id } |
| 131 | ); |
| 132 | } |
| 133 | |
| 134 | if (!botMember.permissions.has(PermissionFlagsBits.ManageRoles)) { |
| 135 | throw createError( |
| 136 | "Missing ManageRoles permission", |
| 137 | ErrorTypes.PERMISSION, |
| 138 | "I need the 'Manage Roles' permission to give verified roles.", |
| 139 | { missingPermission: "ManageRoles" } |
| 140 | ); |
| 141 | } |
| 142 | |
| 143 | if (verifiedRole.id === guild.id || verifiedRole.managed) { |
| 144 | throw createError( |
| 145 | 'Invalid verified role selected', |
| 146 | ErrorTypes.VALIDATION, |
| 147 | 'Please choose a normal assignable role (not @everyone or an integration-managed role).', |
| 148 | { roleId: verifiedRole.id, managed: verifiedRole.managed } |
| 149 | ); |
| 150 | } |
| 151 | |
| 152 | const botRole = botMember.roles.highest; |
| 153 | if (verifiedRole.position >= botRole.position) { |
| 154 | throw createError( |
| 155 | "Role hierarchy error", |
| 156 | ErrorTypes.PERMISSION, |
| 157 | "The verified role must be below my highest role in the server role hierarchy.", |
no test coverage detected