0

I am trying to create an object constructor in a JSON file for Discord. The large constructor is named "person" and I want the objects inside of that to be the Discord Message Author's name, but I can't name the variable "msg.author.username". What should I do?

function person(name, violations, role) {
  this.name = name;
  this.violations = violations;
  this.highestRole = role;
}
var (msg.author.username) = new person(msg.author.username, 1, 
msg.member.highestRole.name)
Logan Cook
  • 13
  • 2
  • Not really sure what you are trying to do ? having the constructor being named what ever `msg.author.username` is ? – WilomGfx Apr 11 '18 at 23:54

1 Answers1

1

You want the variable to be the username? Why? You should be creating a new object out of the person class/object. When you create an object the property will have the name of your user. You should just push the object to a storage data structure. The name of the variable is irrelevant after that point to the actual data.

let storageArr = [];
let new_person = new person(msg.author.username, 1, msg.member.highestRole.name);
storageArr.push(new_person);

It looks like you are new to js, you should read up more on how objects and such work.

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object_prototypes

And if you want to learn it from the top

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps

tehduder9
  • 36
  • 1
  • 2
  • I want it to store each new person separately, and it seems to just replace the last new person. – Logan Cook Apr 12 '18 at 01:11
  • I prevented it from replacing the recently new student by getting rid of the `let storageArr = [];` and putting `let storageArr = require('json file')` in instead – Logan Cook Apr 12 '18 at 01:16