We’re trying to make a command similar to the 8ball example, except it takes the user’s username and computes a hash code to determine the index we pull the response from. This will create a consistent response for each user. The code works, but only for the first person to use the command. If I use the command first, the response will come back for me every time I use it. If another person tries to use it, no response (or error) is sent by Nightbot. If I delete and re-create the command and they use it first, it works for them, but not for me.
I suspect this is due to variable scoping issues, but I don’t know what kind of container these eval commands are run in and the lifecycle of variables used in an eval expression. Any information or pointers are greatly appreciated.
!addcom !team $(eval const responses = ["team 1", "team 2", "team 3", "team 4"];
let hash = 0;
let name = "$(user)";
for (i = 0; i < name.length; i++) {
let char = name.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash;
}
responses[Math.abs(hash % responses.length)];)