I'm trying to get my discord bot to randomly pick messages from a json file and send it every 5*1000 seconds the message interval is working fine earlier.But its sending the same message everytime. Where can i be going wrong?
here is the app.js
const Discord = require('discord.js');
const factDB = require("./replies.json");
const PREFIX = '!';
const client = new Discord.Client();
const fetch = require("node-fetch");
client.once('ready',() =>{
console.log('online!');
});
client.on('message', msg => {
if (msg.content === '?finit') {
const REP = require("./replies.json");
const item = REP[Math.floor(Math.random() * REP.length)];
setInterval(() =>{
msg.channel.send(item.facts);
}, 5 * 1000);
}
});
client.login('token')
here is the json file
[
{
"facts": "1"
},
{
"facts": "2"
},
{
"facts": "3"
},
{
"facts": "4"
},
{
"facts": "5"
}
]
Thank you for reading.