大家好,我想從資料庫中獲取資料,然后顯示為機器人回復。但我有錯誤
這是架構
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);
這就是我呼叫資料的方式
client.on("message", msg => {
if (msg.content === "!n"){
// reply by User find by _id mongoose
const data = User.findOne({ userID: msg.author.id })
const nick = data.nickname;
if (!data) return msg.reply({content: 'You have no data'})
msg.reply({content: `Your nickname is ${nick}`})
}
});
和不和諧的機器人回復
“您的昵稱未定義”
uj5u.com熱心網友回復:
用戶如何保存昵稱?什么是命令?也嘗試console.log(data.nickname)或console.log(nick)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/489434.html
