I am facing an issue with retrieving and displaying data from MongoDB Atlas to use in my Discord bot replies.
Below is the code I used to submit the data:
const subregis = "!reg ign:";
client.on("message", msg => {
if (msg.content.includes(subregis)){
const user = new User({
_id: mongoose.Types.ObjectId(),
userID: msg.author.id,
nickname: msg.content.substring(msg.content.indexOf(":") + 1)
});
user.save().then(result => console.log(result)).catch(err => console.log(err));
msg.reply("Data has been submitted successfully")
}
});
This is my schema:
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const profileSchema = new Schema({
_id: mongoose.Schema.Types.ObjectId,
userID: String,
nickname: String,
});
module.exports = mongoose.model("User", profileSchema);
Despite trying different approaches, I have not been able to display the data as intended. Here's the code snippet I tried:
client.on("message", msg => {
if (msg.content === "!nickname"){
msg.reply("Your Nickname:", User.findById(nickname))
}
});