0

I'm trying to make a notes command for specific users, but my Discord bot makes the notes any note that a user public has said. How do I fix this? I already know the problem with my code, but I don't know how to fix it.

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!"));
}
robyaw
  • 2,274
  • 2
  • 22
  • 29

1 Answers1

0

You have a row called userInfo, this row gets updated whenever someone executes the command. If you want it to link with a user, you're better of using the id of the user because everyone has a different ID. I suggest using something like:

   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!")
Fyxren
  • 250
  • 1
  • 10
  • Thanks, it worked. in the end, I ended up using this code: 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!")); – japanballdev Feb 22 '21 at 13:24