0
votes

I'd like my bot to send a message and then edit it once per minute with the following value:

client.users.cache.size

I tried the following code, but unfortunately, it did not work.

const timejkdfg = new MessageEmbed().setTitle("testing").addField(":", client.users.cache.size);
message.channel.send(timejkdfg).then((msggg) => {
    const timejk1dfg = new MessageEmbed().setTitle("testing").addField(":", client.users.cache.size);
    setInterval(function () {
        msggg.edit(`${timejk1dfg}`);
    }, 60000);
});

Instead of showing the number of users cached, it shows "[object Object]".

1

1 Answers

0
votes

Your current code runs every minute but it doesn't have the effect you want it to have. That is because you create the timejk1dfg constant outside of the setInterval function. That means it will only be created once and after that it is always the same, not really what you want here. The fix is pretty easy, just move timejk1dfg into the Interval and remove the string from your .edit.

const embed = new Discord.MessageEmbed().setTitle("testing").addField(":", client.users.cache.size);
message.channel.send(embed).then((msg) => {
    setInterval(function () {
        const embed = new Discord.MessageEmbed().setTitle("testing").addField(":", client.users.cache.size);
        msg.edit(embed);
    }, 6000);
});

NOTE: I made your naming a little more conventional

As to your problem of client.users.cache.size showing [object Object], I couldn't replicate that. I suggest a console.log(client.users.cache) to see what is actually in there.