
Ben S. answered 05/11/21
Full stack developer specializing in React and Rails
Hi T.K.
It looks like that code will have a bug due to an issue with scope.
Inside your setInterval callback function you've defined a variable "fact," but then you try to reference fact outside of that scope on the line where you write "message.channel.send(facts[fact]);" This should cause a reference error.
You can declare var fact outside the setInterval function, then reassign its value inside the interval, allowing you to have access to fact in the global scope. This should at least solve the reference error.
I'm not sure what other issues you may have in regards to the discord API, but hopefully you find this helpful in improving your knowledge of JavaScript :)