const { ButtonInteraction, EmbedBuilder, AttachmentBuilder, ButtonBuilder, ActionRowBuilder, ButtonStyle } = require("discord.js") const { Captcha } = require("captcha-canvas") module.exports = { id: "verification", /** * * @param {ButtonInteraction} interaction */ async execute(interaction) { const captcha = new Captcha(); //create a captcha canvas of 100x300. captcha.async = false //Sync captcha.addDecoy(); //Add decoy text on captcha canvas. captcha.drawTrace(); //draw trace lines on captcha canvas. captcha.drawCaptcha({ characters: 6, size: 40, font: 'Sans', skew: true, colors: [], rotate: 5, color: '#32cf7e', opacity: 0.8, }); //draw captcha text on captcha canvas. console.log(captcha.text); //log captcha text. const completedEmbed = new EmbedBuilder() .setColor("Green") .setDescription("Du bestod din Captcha.") const incorrectEmbed = new EmbedBuilder() .setColor("Red") .setDescription("Du fejlede din Captcha.") const errorEmbed = new EmbedBuilder() .setColor("Red") .setDescription("Captchaen fejlede. Prøv igen senere, eller kontakt en staff.") const attachment = new AttachmentBuilder(captcha.png, {name: "captcha.png"} ) const Embed = new EmbedBuilder() .setColor(0x0051ff) .setDescription("Din captcha er her:") .setImage("attachment://captcha.png") await interaction.reply({files: [attachment], embeds: [Embed], ephemeral: true}) const verificationRole = interaction.guild.roles.cache.find(role => role.name === "Verified"); const unverifiedRole = interaction.guild.roles.cache.find(role => role.name === "Unverified"); try { const filter = (msg) => { return !msg.author.bot; }; const collector = interaction.channel.createMessageCollector({ filter, time: 15000, max: 1 }); collector.on('collect', async m => { console.log(`Collected ${m.content}`); if(m.content === captcha.text) { await m.delete(); await interaction.member.roles.add(verificationRole) await interaction.member.roles.remove(unverifiedRole) await interaction.followUp({embeds: [completedEmbed], ephemeral: true}) } else { await m.delete(); await interaction.followUp({embeds: [incorrectEmbed], ephemeral: true}) } }); collector.on('end', async collected => { console.log(`Collected ${collected.size} items`) }); } catch { await interaction.followUp({embeds: [errorEmbed], ephemeral: true}) } } }