0

So I have a discord bot that stores users in-game username and puts it into a text file.

var name1 = { 
    discordID: 438081715576242176,
    apexNAME:  test1
}
var name2 = { 
    discordID: 438081715576242176,
    apexNAME:  test2
}

like this.

If the user writes !stats then if their discordID matches the writers discordID in discord then send apexNAME.

Rup
  • 33,765
  • 9
  • 83
  • 112
Zenzari
  • 21
  • 3
  • I'm not sure exactly what you're asking: how to look up the record from your text file? Have you actually written it as a list of `var nameX = { };` statements? You probably want to use a database instead, e.g. NeDB ([other ideas here](https://stackoverflow.com/q/7233057/243245)). If you did want to use a file like this, write a JSON array or map instead. – Rup Jun 21 '20 at 09:36
  • In discordjs (node i assume) when member sends a message it triggers a on_message event for Client so when the event is triggered use message.author property to match id. please take a look at discord js doc https://discordjs-fork.readthedocs.io/en/latest/ – midugh Jun 21 '20 at 09:44

1 Answers1

1

If you were storing with a text file, you would need to store it plainly and use split and joins to return after retrieving it with node fs.

My advice is to check out the sections of the discord.js guide relating persisting data

https://discordjs.guide/keyv/#installation

In my bot i use sequelize, there is an example of using it on that page aswell.

James mcconnon
  • 579
  • 5
  • 23