I have code that should edit a discord message per each execution. Everything seems to be work fine, but when I add interval functionality(to execute it code every minute) it couldn't edit bot message anymore:
call:
setInterval(function () { var data = getData(response, list); editMessage(data) }, 60000)
function with message edit
function editMessage(data) {
client.on('ready', () => {
client.guilds.cache.get('server').channels.cache.get('channel').messages.fetch('message').then(message => {
message.edit('new message content');
}).catch(err => {
console.error(err);
});;
});
}
So I can receive the data inside editMessage function, but anything that goes inside of client.on('ready', () => {... can't be engaged with interval function. What could be the case?
I'm using Discord.js 12 version.
Just for the record, I made this work in a different approach. I've wrapped the setInterval function inside of client.on and it works as intended.
client.on('ready', () => {
client.guilds.cache.get('server').channels.cache.get('channel').messages.fetch('message').then(message => {
setInterval(function () {
message.edit('new message content');
console.log('new message content')
}, 1 * 30000);
}).catch(err => {
console.error(err);
});;
});