Unique variable for every person

Hello! These past days I’ve made a cuople of these, but the more I learn the lass they’ll appear.

This time I’m wondering if there’s a way to make a variable unique to one person.

Here’s an example of what I’d like to do.

client.on('message', message => {
if(message.content.startsWith(`1`)) {
var personalVar = 1
}
if(message.content.startsWith(`2`)) {
var personalVar = 2
}
if(message.content.startsWith(`check`)) {
message.channel.send(personalVar)
}
})

This would lead to this

Person1:
1
Person2:
2
Person1:
check
Bot:
1
Person2:
check
Bot:
2

Do you understand what I want?

As always, thanks in advance!

1 Like

i will set up the newest dev version if ya need it

done, easiest thing eva

umh what? I don’t think I quite understand…

if you use a database, each user has an entire array to themselves, and that means that array can be considered a personal variable, and just pull that from the database, you got a unique variable.

Sorry if I seem stupid or something, it’s just that I’m really new to all of this. And how do I create a database in glitch?

1 Like

send me the project link, i will make one for you :stuck_out_tongue:
i know what you mean,
i was confused when i first made a db XD

Well, first off I need to move the tokens to the .env-file, but i get errors like: .env: line 2: [The token I want to define]: command not found.

it was because of those I just didn’t move them in the first place

just send the link, i will assist with all of this

but then you’ll see the bot-token, which is like THE rule when it comes to this

i dont steal, i have been here since september, a very loyal person, i only wish to ever help

Call me naive, but by the way you behave in this chat I actually feel like I can trust you so…

do you know how to dm in glitch?

if you do, i would suggest messaging me the link, just for safety

just did, here you go

glitch has had a fit

First off, I would not recommend adding someone to your project, but instead, remixing that and giving that to them. Then, instead of having someone do the work for you, I would research a bit on how to store data in a database. And once you know that, you will learn how to do it yourself instead of asking someone else to do it for you.

As they say, give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime.

Have a great day!

1 Like

coding, its ok, he/she is still a beginner and of course, every beginner needs a bit of help when they want to do something they never did before.
anyways… i’m already almost done with helping him

So from what I can see, a person has to send a number and when the person sends check your bot replies with the said number? Correct me if I am wrong.

If thats the case, make use of Collections, Collection is a class that extends the Javasript Built-in Map Object and is used throughout discord.js rather than Arrays for anything that has an ID, for significantly improved performance and ease-of-use.

You create a Collection the same way how you would make a Map:
var myCollection = new Discord.Collection();

I prefer to define it like this:
client.myCollection = new Discord.Collection();

Your code makes sense but when you define a variable inside a an if statement you cannot call it outside the { }

The collection is just something I think is smart. You should read the hyperlink I attached in the 3rd sentece. Tip: <Collection>.set(message.author.id, "Your turn")

Have a nice day and feel free to correct me

Hey there,

I am sorry to say, however, you’re misguiding him by providing fallacious information, since a variable invoked or created with var can be used outside a block (not a scope), such as if-statements, loops, etc.

For instance, the following code will work just fine

if (true) {
  var str = 'test';
}
console.log(str); // 'test'

Happy Glitching!