为什么这种不和谐.js对猫鼬的查询不起作用?



我尝试使用discord.js命令向mongoodb提交数据,为什么这个代码不起作用?

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.text.substr(9)
});
user.save().then(result => console.log(result)).catch(err => console.log(err));
msg.reply("Data already submited")
}
})

我尝试了不同的方法来找到你的问题,我想我找到了问题。这是我修改后的代码:

// you could also do rather than .includes, you could do if (message.content === "!reg ign: ") rather than having to make it more complicated
// maybe change substr to substring although they both work also there is no message.content.text so I fixed that
// you could create a const text = args[0]; where it will fetch the users first text displayed example: "!reg ing hello" and I will have a username called hello
client.on("message", msg => {
if (msg.content === "!reg ign: "){ 
const user = new User({
_id: mongoose.Types.ObjectId(),
userID: msg.author.id,
Nickname: msg.content.substring(msg.content.indexOf(":" + 1) // so basically anything after the : will be the username
});
user.save().then(result => console.log(result)).catch(err => console.log(err));
msg.reply("Data has been submitted successfully") 
}
});

最新更新