I am coding a premium system for my bot and it worked for like 1 day. Now I am getting this error. I hope somebody can help me! It would be really cool! https://imgur.com/a/NVfjB7l
This is my error message. I tried to solve it for 2 days but never find an answere. Hopefully you can.
Here is my code:
const { Command } = require("reconlx");
const moment = require("moment");
const schema = require("../../Models/code.js");
const User = require("../../Models/User");
module.exports = new Command({
// options
name: "redeem",
description: `redeem preium code`,
userPermissions: ["ADMINISTRATOR"],
category: "Premium",
options: [
{
name: "code",
description: `give me code`,
type: "STRING",
required: true,
},
],
// command start
run: async ( client, interaction, args ) => {
// Code
// Check if the user with a unique ID is in our database.
let user = await User.findOne({ Id: interaction.member.id });
// Check Users input for a valid code. Like `!redeem ABCD-EFGH-IJKL`
let code = interaction.options.getString("code");
// Return an error if the User does not include any Premium Code
if (!code) {
interaction.followUp(`**Please specify the code you want to redeem!**`);
}
// If the user is already a premium user, we dont want to save that so we return it.
if (user && user.isPremium) {
return interaction.followUp(`**> You already are a premium user**`);
}
// Check if the code is valid within the database
const premium = await schema.findOne({
code: code.toUpperCase(),
});
// Set the expire date for the premium code
if (premium) {
const expires = moment(premium.expiresAt).format(
"dddd, MMMM Do YYYY HH:mm:ss"
);
// Once the code is expired, we delete it from the database and from the users profile
if (moment().isAfter(premium.expiresAt)) {
premium.remove();
user.isPremium = false;
User.save();
return interaction.followUp(
`**> The code you have entered is expired!**`
);
}
// Save the User within the Database
user = await user.save({ new: true }).catch(() => {});
client.userSettings.set(interaction.member.id, user);
await premium.deleteOne().catch(() => {});
// Send a success message once redeemed
interaction.followUp(
`**You have successfully redeemed premium!**nn`Expires at: ${expires}``
);
// Error message if the code is not valid.
} else {
return interaction.followUp(
`**The code is invalid. Please try again using valid one!**`
);
}
},
});
It was running for 1 Day. Idk how lol. But after I woke up and wanted to redeem a code. It says the error.
Maybe one of you knows why.