问题描述
我正在尝试为特定用户创建注释命令,但我的 discord 机器人将注释记录为用户公开说过的任何注释。我该如何解决?我已经知道我的代码有问题,但我不知道如何解决。
if (command == "Note") {
const notes = db.fetch('userInfo');
while (!args[0]) return message.channel.send("Here are your notes: " + notes);
db.set('userInfo',args.join(' '));
message.channel.send((args.join(' ')) + (" successfully noted!"));
}
解决方法
您有一个名为 userInfo
的行,只要有人执行命令,该行就会更新。如果您希望它与用户链接,最好使用用户的 id,因为每个人都有不同的 ID。我建议使用类似的东西:
const notes = db.fetch(`userInfo.${message.author.id}`)
while (!args[0]) return message.channel.send("Here are your notes: " + notes )
db.set('userInfo.${message.author.id}',args.join(' '))
message.channel.send(args.join(' ') + " successfully noted!")