UNPKG

discord-guard

Version:

A discord verifacation bot that uses a captcha.

76 lines (75 loc) 3.57 kB
class Guard { constructor(token) { this.token = token; } start(channelID, roleName) { const { createCaptcha } = require("./captcha") const fs = require("fs"); const Discord = require('discord.js') const bot = new Discord.Client() const colors = require('colors') bot.login(this.token) bot.once('ready', () => { console.log('Starting server Guarding system...'.bgBlue.green) const error = require('./Client/error') error(bot) const warn = require('./Client/warn') warn(bot) const disconnect = require('./Client/disconnect') disconnect(bot) const reconnect = require('./Client/reconnect') reconnect(bot) const ready = require('./Client/ready') ready(bot) }) bot.on('message', async message => { if (message.author.bot) return; if (message.channel.type === 'dm') return; if (message.channel.id !== channelID) return; message.delete() if (message.content === 'verify') { const captcha = await createCaptcha(); try { const msg = await message.author.send(`Welcome ${message.author}! \nPlease make sure to read the rules. \n\nWelcome to Froggits Grassland. \n• This is toads development server that is run by a bot called froggit.\n\n**Please enter the given captcha below to verify**. \n(*__you have 30 minutes to enter the captcha or you will be kicked__*)`, { files: [{ attachment: `./Src/Container/${captcha}.png`, name: `${captcha}.png` }] }); try { const filter = m => { if (m.author.bot) return; if (m.author.id === message.member.id && m.content === captcha) return true; else { m.channel.send('You entered the captcha incorrectly.'); return false; } }; const response = await msg.channel.awaitMessages(filter, { max: 1, time: 600000, errors: ['time'] }); if (response) { await msg.channel.send(`You have verified yourself in ${message.guild.name}`); let role = await message.guild.roles.cache.find(role => role.name === roleName); await message.member.roles.add(role); await fs.unlink(`./Src/Container/${captcha}.png`, function (err, result) { if (err) console.log('error', err) }) return; } } catch (err) { console.log(err); await msg.channel.send('You did not solve the captcha correctly on time.'); await message.member.kick(); await fs.unlink(`./Src/Container/${captcha}.png`) .catch(err => console.log(err)); } } catch (err) { console.log(err); } } return; }) } } module.exports.Guard = Guard;