const { SlashCommandBuilder } = require("discord.js"); const nodemailer = require("nodemailer"); const VerificationCode = require("../models/VerificationCode"); const transporter = nodemailer.createTransport({ service: "Gmail", auth: { user: process.env.EMAIL_USER, pass: process.env.EMAIL_PASS, }, }); module.exports = { data: new SlashCommandBuilder() .setName("verify") .setDescription("Verify your account with an email address") .addStringOption((option) => option .setName("email") .setDescription("Your DCU email address") .setRequired(true) ), async execute(interaction, client) { const email = interaction.options.getString("email"); const emailDomain = email.split("@")[1]; const EMAIL_DOMAINS = process.env.EMAIL_DOMAINS.split(","); if (!EMAIL_DOMAINS.includes(emailDomain)) { return interaction.reply({ content: "You must use a valid DCU email address.", ephemeral: true, }); } const guild = client.guilds.cache.get(process.env.GUILD_ID); if (!guild) { console.error("Guild not found."); return interaction.reply({ content: "Guild not found.", ephemeral: true, }); } const member = guild.members.cache.get(interaction.user.id); if (!member) { console.error("Member not found in the guild."); return interaction.reply({ content: "Member not found in the guild.", ephemeral: true, }); } const role = guild.roles.cache.find( (r) => r.name === process.env.VERIFIED_ROLE_NAME ); if (!role) { console.error(`Role "${process.env.VERIFIED_ROLE_NAME}" not found.`); return interaction.reply({ content: `Role "${process.env.VERIFIED_ROLE_NAME}" not found.`, ephemeral: true, }); } if (member.roles.cache.has(role.id)) { return interaction.reply({ content: "You are already verified!", ephemeral: true, }); } const verificationCode = Math.floor( 100000 + Math.random() * 900000 ).toString(); const emailHtml = `
Hi there,
Your Esports verification code is:
This code is valid for 10 minutes. Use it with the command /code your_code
.
If you did not request this code, please ignore this email.
Best regards,
Esports Committee