const discord = require("discord.js"); const colors = require("../colors.json"); const botconfig = require("../botconfig.json"); const mongoose = require("mongoose"); module.exports.run = async (bot, message, args) => { const embed = new discord.MessageEmbed(); const Newembed = new discord.MessageEmbed(); mongoose.connect(botconfig.mongoPass, { useNewUrlParser: true, useUnifiedTopology: true }); const chanIDs = require("../models/guild.js"); chanIDs.findOne({ channelID: message.channel.id }, (err, data) => { if(err) console.log(err); if(!data) { const newchanIDs = new chanIDs({ name: message.guild.name, guildID: message.guild.id, channelID: message.channel.id, ownerID: message.guild.owner.id, }) newchanIDs.save().catch(err => console.log(err)); var pick = colors[Math.floor(Math.random() * colors.length)]; embed.setTitle(`Successfully Added:`); embed.setColor(pick); embed.addField(`Channel Name`, message.channel.name); embed.addField(`Channel ID`, message.channel.id); embed.addField(`Guild ID`, message.guild.id); embed.addField(`Channel Opted In By`, message.author.username); return message.channel.send(embed) } else { Newembed.setTitle(`ERROR:`); Newembed.setColor(colors.red); Newembed.setDescription(`You have already opted a channel in this guild!`); Newembed.setFooter('Please use `?optout` if you wish to opt-in on a new channel!'); return message.channel.send(Newembed) } }); } module.exports.help = { name: "optin", aliases: ["opt", "optadd"] }