Skip to content

Instantly share code, notes, and snippets.

@sell
Created May 29, 2021 05:56
Show Gist options
  • Save sell/ce6d42c19354e085d5acde7b3b52a8f8 to your computer and use it in GitHub Desktop.
Save sell/ce6d42c19354e085d5acde7b3b52a8f8 to your computer and use it in GitHub Desktop.
const { MessageEmbed } = require('discord.js');
const axios = require('axios');
const url = 'https://api.no-api-key.com/api/v2/captcha';
module.exports = {
name: "verify",
run: async (client, message, args) => {
const filter = m => m.content && m.author.id === message.author.id;
const verifiedRole = message.guild.roles.cache.find(role => role.name === 'verified');
if (message.member.roles.cache.has(verifiedRole.id)) {
message.delete()
return;
}
console.log(message.member.roles)
const { data } = await axios.get(url);
console.log(data)
const embed = new MessageEmbed()
.setTitle('Fill Out Captcha')
.setDescription('You have 30 Seconds to complete the captcha.')
.setImage(data.captcha)
await message.channel.send(embed)
const collector = message.channel.createMessageCollector(filter, { time: 30000 });
collector.on('collect', m => {
console.log(`Collected ${m.content}`);
if (m.content !== data.captcha_text) {
message.channel.send('Incorrect code, try again!')
.then(m => m.delete({ timeout: 2000 }))
}
if (m.content === data.captcha_text) {
message.channel.send('You entered code correctly & are now verified!')
.then(m => m.delete({ timeout: 10000 }));
collector.stop();
message.member.roles.add(verifiedRole);
}
});
collector.on('end', collected => {
console.log(`Collected ${collected.size} items`);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment