Question: I'm trying to code a discord bot that edits the same message that it just sent every few minutes, I have some code already written but it only edits it once. I'm new to this style of thing, any idea what could be wrong or what I need to do?

This is supposed to edit with my FiveM Server but I want to get the editing part done first

I've tried using `setTimeout()` in my message but it only edits the message once.

```
const config = require("./config.js");
const request = require('request');

const Discord = require('discord.js');
const client = new Discord.Client();

var ip = "Private"
var port = "30120"
var timeoutvar = "60000"

const players = request(`http://${ip}:${port}/players.json`, function (players, error, response, body) {
  console.log('body:', body);
});

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

// Set the bot's presence (activity and status)
client.on("ready", () => {
  client.user.setPresence({
      game: { 
          name: 'MODPS',
          type: 'WATCHING'
      },
      status: 'dnd'
  })
})

client.on('message', msg => {
  client.channels.get("channelid").send(`${players}`)
  .then((msg) => {
    setTimeout(function() {
      msg.edit(`${players}`)
    }, 2000)}
  )}
)

client.login(token);

```

Expected result: the message to be edited at least every minute or so.

Actual result: only edits the same message once.

Answer: 
You can do it using [`setInterval()`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval) method.

> 
> The `setInterval()` method repeatedly calls a function or executes a code snippet, with a fixed time delay between each call.
> 
> 
> 

```
client.on('message', msg => {
    client.channels.get("channelid").send(`${players}`)
    .then((msg) => {
        setInterval(function() {
            msg.edit(`${players}`)
        }, 1000)} /* 1000 ms = 1 second */
    )}
)

```

Here is the basic example of `setInterval()` method:

```js
setInterval(function(){
  console.log('Hello World');
}, 2000);
```
60,000 milliseconds = 60 seconds. `setInterval` executes the given function each `x` milliseconds:

```
client.on('message', msg => {
  client.channels.get("channelid").send(`${players}`)
  .then((msg) => {
    setInterval(function() {
    msg.edit(`${players}`)
  }, 60000)}
  )}
)

```