//ERROR 1 (there will def be more errors, trust me) (node:89936) UnhandledPromiseRejectionWarning: TypeError: db.findOne is not a function at Object.execute (C:\Users\shree\Desktop\Discord Bots\DiscordBot\commands\warn.js:11:12) at module.exports (C:\Users\shree\Desktop\Discord Bots\DiscordBot\events\guild\message.js:58:17) at processTicksAndRejections (internal/process/task_queues.js:93:5) (node:89936) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:89936) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. //MAIN.JS const Discord = require('discord.js'); require('dotenv').config(); const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION"] }); const mongoose = require('mongoose'); const YouTubeNotifier = require('youtube-notification'); const got = require('got'); const memberCounter = require('./counters/member-counter') client.once('ready', () => { client.user.setActivity('for bored people', { type: 'WATCHING' }); // Status memberCounter(client); }); client.on('guildMemberAdd', guildMember =>{ let nRole = guildMember.guild.roles.cache.find(role => role.name === 'Notification Squad'); const embed = new Discord.MessageEmbed() .setColor('#c21000') .setDescription(`Welcome <@${guildMember.user.id}> to our server! Make sure to check out the rules channel!`) .setFooter(`Member # ${guildMember.guild.memberCount}`) guildMember.roles.add(nRole) guildMember.guild.channels.cache.get('796463272562917396').send(embed) }); client.on('guildMemberAdd', guildMember =>{ let nRole = guildMember.guild.roles.cache.find(role => role.name === `⠀⠀⠀⠀ Shramen Socials⠀⠀⠀⠀`); guildMember.roles.add(nRole) }); client.on('guildMemberAdd', guildMember =>{ let nRole = guildMember.guild.roles.cache.find(role => role.name === `⠀⠀⠀⠀⠀⠀⠀ ⠀ Colors⠀⠀⠀⠀`); guildMember.roles.add(nRole) }); client.on('guildMemberAdd', guildMember =>{ let nRole = guildMember.guild.roles.cache.find(role => role.name === `⠀⠀⠀⠀⠀⠀ Pronouns⠀⠀⠀⠀`); guildMember.roles.add(nRole) }); client.on('guildMemberAdd', guildMember =>{ let nRole = guildMember.guild.roles.cache.find(role => role.name === 'You Exist! CONGRATS!'); guildMember.roles.add(nRole) }); client.on('guildMemberAdd', guildMember =>{ let nRole = guildMember.guild.roles.cache.find(role => role.name === `⠀⠀⠀⠀⠀⠀⠀ Twitch Follow/Sub⠀⠀⠀⠀⠀⠀⠀`); guildMember.roles.add(nRole) }); client.on('guildMemberAdd', guildMember =>{ let nRole = guildMember.guild.roles.cache.find(role => role.name === `⠀⠀⠀⠀⠀⠀⠀ Country Roles⠀⠀⠀⠀⠀⠀⠀⠀`); guildMember.roles.add(nRole) }); client.commands = new Discord.Collection(); client.events = new Discord.Collection(); ['command_handler', 'event_handler'].forEach(handler => { require(`./handlers/${handler}`)(client, Discord); }) mongoose.connect(process.env.MONGODB_SRV, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false }).then(()=>{ console.log('Connected to the database!') }).catch((err) =>{ console.log(err); }) client.login(process.env.TOKEN); //WARNS.JS in Models folder const db = require('../models/warns') const { Message, MessageEmbed } = require('discord.js') const { Mongoose } = require('mongoose') const mongoose = require(`mongoose`) let Schema = new mongoose.Schema({ guildid: String, user: String, content: Array }) module.exports = { name :'warns', async execute(client, message, args){ if(!message.member.roles.cache.has('808043455255150612')) return message.channel.send('You do not have permissions to use this command.') const user = message.mentions.members.first() || message.guild.members.cache.get(args[0]) if(!user) return message.channel.send('User not found.') const reason = args.slice(1).join(" ") db.findOne({ guildid: message.guild.id, user: user.user.id}, async(err, data) => { if(err) throw err; if(data) { message.channel.send(new MessageEmbed() .setTitle(`${user.user.tag}'s warns`) .setDescription( data.content.map( (w, i) => `\`${i + 1}\` | Moderator : ${message.guild.members.cache.get(w.moderator).user.tag}\nReason : ${w.reason}` ) ) .setColor("RED") ) } else { message.channel.send('User has no warns') } }) } } //WARN.JS const db = require('../models/warns') const { Message, MessageEmbed } = require('discord.js') module.exports = { name :'warn', async execute(client, message, args, cmd, Discord, profileData){ if(!message.member.hasPermission('KICK_MEMBERS')) return message.channel.send('You do not have permissions to use this command.') const user = message.mentions.members.first() || message.guild.members.cache.get(args[0]) if(!user) return message.channel.send('User not found.') const reason = args.slice(1).join(" ") db.findOne({ guildid: message.guild.id, user: user.user.id}, async(err, data) => { if(err) throw err; if(!data) { data = new db({ guildid: message.guild.id, user : user.user.id, content : [ { moderator : message.author.id, reason : reason } ] }) } else { const obj = { moderator: message.author.id, reason : reason } data.content.push(obj) } data.save() }); user.send(new MessageEmbed() .setDescription(`You have been warned for ${reason}`) .setColor("RED") ) message.channel.send(new MessageEmbed() .setDescription(`Warned ${user} for ${reason}`).setColor('RED') ) } } //RWARN.JS const db = require('../models/warns') module.exports = { name : 'rwarn', async execute(client, message, args, cmd, Discord, profileData){ if(!message.member.hasPermission('KICK_MEMBERS')) return message.channel.send('You do not have permission to use this command.') const user = message.mentions.members.first() || message.guild.members.cache.get(args[0]); if(!user) return message.channel.send('User not found.') db.findOne({ guildid : message.guild.id, user: user.user.id}, async(err,data) => { if(err) throw err; if(data) { let number = parseInt(args[1]) - 1 data.content.splice(number, 1) message.channel.send('removed a warning') data.save() } else { message.channel.send('This user does not have any warns') } }) } } //CLEARWARNINGS.JS const db = require('../models/warns') module.exports = { name : 'clearwarnings', aliases: ["cwarns"], async execute(client, message, args, cmd, Discord, profileData){ if(!message.member.hasPermission('ADMINISTRATOR')) return message.channel.send('You do not have permission to use this command.') const user = message.mentions.members.first() || message.guild.members.cache.get(args[0]); if(!user) return message.channel.send('User not found.') db.findOne({ guildid : message.guild.id, user: user.user.id}, async(err,data) => { if(err) throw err; if(data) { await db.findOneAndDelete({ user : user.user.id, guildid: message.guild.id}) message.channel.send(`Cleared ${user.user.tag}'s warns`) } else { message.channel.send('This user does not have any warns') } }) } } //MESSAGE.JS const profileModel = require("../../models/profileSchema"); const { MessageEmbed } = require('discord.js') const cooldowns = new Map(); const db = require('../../models/warns') module.exports = async (Discord, client, message) => { const prefix = '-'; if(!message.content.startsWith(prefix) || message.author.bot) return; let profileData; try { profileData = await profileModel.findOne({ userID: message.author.id }); if(!profileData){ let profile = await profileModel.create({ userID: message.author.id, serverID: message.guild.id, coins: 1000, bank: 0, }); profile.save(); } } catch (err) { console.log(err); } const args = message.content.slice(prefix.length).split(/ +/); const cmd = args.shift().toLowerCase(); const command = client.commands.get(cmd) || client.commands.find(a => a.aliases && a.aliases.includes(cmd)); if(!cooldowns.has(command.name)){ cooldowns.set(command.name, new Discord.Collection()); } const current_time = Date.now(); const time_stamps = cooldowns.get(command.name) const cooldown_amount = (command.cooldown) * 1000; if(time_stamps.has(message.author.id)){ const expiration_time = time_stamps.get(message.author.id) + cooldown_amount; if(current_time < expiration_time){ const time_left = (expiration_time - current_time) / 1000; const embed = new MessageEmbed() .setColor(`#c21000`) .setTitle(`---MESSAGE COOLDOWN---`) .setDescription(`Please wait ${time_left.toFixed(1)} more seconds before using ${command.name}`) return message.channel.send(embed) } } time_stamps.set(message.author.id, current_time) setTimeout(() => time_stamps.delete(message.author.id), cooldown_amount); try{ command.execute(client, message, args, cmd, Discord, profileData); } catch (err){ message.reply("Sorry, there was an error when trying to execute that command"); console.log(err); } }