'User.save is not defined [ discord.js and mongoose ]
Here is my bot main code which is related to the error
global.mongoose = require('mongoose')
const config = require('./settings.json')
global.Guild = require("./data/guild.js");
global.User = require('./data/user.js');
let random = Math.floor(Math.random() * 5)
User.money += random;
User.xp++
User.messages++
if(User.xp >= config.upXP){
let embed = new Discord.MessageEmbed()
.setColor(config.color)
.setDescription(`[:tada:] Congratulations to **${message.author.username}** on your new level!`)
message.channel.send({ embeds: [embed] });
User.xp -= config.upXP;
User.level+=1
};
User.save();
if (!message.content.startsWith(Guild.prefix)) return;
const args = message.content.slice(Guild.prefix.length).trim().split(/ +/g);
const cmdName = args.shift().toLowerCase();
const command = client.commands.get(cmdName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(cmdName));
if(!command) return;
if(!require('./settings.json').owner.includes(message.author.id) && command.public === false) return;
command.execute(bot, message, args, config);
})
This comes as a error
User.save(); ^
TypeError: User.save is not a function
I tried doing the markModified() function but it gave me null value . None of google solutions worked. I am working on replit and nodejs 16 .
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
